>This seems like a scenario where you would want system() to require
>pthread_atfork() handlers to be called. Aside from that, it seems somewhat
>contradictory that system() "shall behave as if a child process were created
>using fork()..." but it is undefined if pthread_atfork() handlers are called
.
>
The reason it likely that the implementer of system() and popen() get the
freedom to use a more efficient mechanism.
In the case of Solaris, we have been using posix_spawn(); originally
implemented on top of vfork() & execve(), in Solaris 11.4 it is an actual
system call. No call to fork() even under the covers.
The vfork() used before also did not call the pthread_atfork() handlers
either.
If you have control over the callers of system(), you could replace those
with posix_spawn() and have posix_spawn attributes in place to close the
specific file descriptors.
Casper