3 ms·
Note that posix says you shouldn't do anything except immediately call exec after fork in multithreaded programs.
by tedunangst 7y ago
Note that posix says you shouldn't do anything except immediately call exec after fork in multithreaded programs.
- klodolph 7y agoThis is not true. IIRC, you can do anything as long as you don’t call any function which is not async signal safe. Otherwise, it would be very difficult to do simple things like run a child process in a separate directory (with chdir()), or report a failed exec() to the parent. The typical way to report errors upwards is to create a pipe with CLOEXEC and then write the error code to it from the child if exec fails. This requires at least calling write(). You may be remembering vfork(), which is a bit of an obsolete API.
- tedunangst 7y agoAh, yes, I overstated the case. Thanks for clarifying the rule is only signal safe functions. Notably, this excludes malloc, etc. (I was thinking as I posted I should dig up the relevant quote just to be sure. Oops.)