This question has been asked several times here, but I can't find answer开发者_如何学JAVA for the following situation:
My program uses statically linked libraries, which open file handles, so, I'm unable to set FD_CLOEXEC on those file handles
simply calling exec causes alot of errors in new process, because of unavailable file handles
Basically I need:
1. spawn new process without blocking current one 2. terminate current process (close all handles)Can I do it on linux?
Closing all filedescriptors should be as simple as
#include <unistd.h>
for (i=getdtablesize();i>=0;--i)
close(i); /* close all descriptors */
This is also a standard step during daemonizing, see e.g. http://www.enderunix.org/docs/eng/daemon.php
精彩评论