Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This function may do mostly the right thing in a process dedicated to it, but it is not safe to call as part of a more complex process - especially a multi-threaded one.

For example, malloc() may be holding on to a mutex in the parent process (on another thread), so subsequent malloc() calls in the child process will block waiting for the mutex to be released. Closing the file handles may help if this was a kernel mutex, but it may not help if this was a user-space mutex.

In general, fork() without exec() is only safe as the first thing done in a process.

Also, it looks like there is a minor race condition in the implementation: since the original process exit()s immediately after the fork(), control will return to its parent, which may close the session - this could happen before the child had a chance to call setsid() and detach from the parent session.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: