Operating System - HP-UX
1748113 Members
3302 Online
108758 Solutions
New Discussion

Re: system() call in a multi thread environment

 
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
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.