Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

system() call in a multi thread environment

 
Highlighted
Fedele Giuseppe
Frequent Advisor

system() call in a multi thread environment

Hello,

can I use "system()" system call in a multi-thread environment?

I know that such a call is NOT thread-safe.

Can I use a mechanism based on MUTEX variables, like:

if(pthread_mutex_trylock(&) == 0)
{
....
system( ....
pthread_mutex_unlock(&);
}

?

Thanks in advance

Giuseppe
1 REPLY 1
Highlighted
Dennis Handly
Acclaimed Contributor

Re: system() call in a multi thread environment

I forget exactly why calling system(3) is a bad idea with threads.

Your mutex will synchronize the use, so you can try it.
But there may be other issues with the fork, exec, wait and the signal masking.