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

"system" call in multithreading env

 
Highlighted
Fedele Giuseppe
Frequent Advisor

"system" call in multithreading env

Hi all,

I have a program in C code in which I would introduce the thread mechanisms.

The program uses "system" call and I know that it is not thread-safe.

My question is: can I use "system" in main-thread only? Or is it forbidden also here?

Thanks and Regards

Giuseppe
5 REPLIES 5
Highlighted
Dennis Handly
Acclaimed Contributor

Re: "system" call in multithreading env

The problem with system(3) is that is calls fork/exec. This means the atfork handlers have to fire off and any signal handling required to wait for the child has to be done.

That said, I don't know if limiting it to the main thread will be good enough.
Highlighted
Fedele Giuseppe
Frequent Advisor

Re: "system" call in multithreading env

Hi,
could you better explain how to manage signals in such a context?

The standard signal handling must be modified?

Thanks

Giuseppe
Highlighted
Dennis Handly
Acclaimed Contributor

Re: "system" call in multithreading env

>could you better explain how to manage signals in such a context?

You may not able to do that because system(3) has to handle SIGCHLD and may mess up your handler.
Highlighted
Fedele Giuseppe
Frequent Advisor

Re: "system" call in multithreading env

Can I use fork/execl instead of "system" ?

I know these two calls are thread safe ...

Giuseppe
Highlighted
Dennis Handly
Acclaimed Contributor

Re: "system" call in multithreading env

>Can I use fork/execl instead of "system"?

Sure. Provided you know how to implement what you are passing to system(3).