Jeff Hostetler <git@xxxxxxxxxxxxxxxxx> writes: > The original problem was that chdir() is not safe in a multi-threaded > process because one thread calling chdir() will affect any concurrent > file operations (open(), mkdir(), etc.) that use relative paths. > > I think Adding a fork() at this layer would just create new types of > problems. For example, if another thread was concurrently writing to > a socket while we were setting up this new socket, we would suddenly > have 1 thread in each process now writing to that socket and the > receiver would get a mixture of output from both processes. Right? cf. https://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html The fork() function shall create a new process. The new process (child process) shall be an exact copy of the calling process (parent process) except as detailed below: ... * A process shall be created with a single thread. If a multi-threaded process calls fork(), the new process shall contain a replica of the calling thread and its entire address space, possibly including the states of mutexes and other resources. Consequently, to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the exec functions is called. So, probably not.