开发者

C++ start new process and terminate the current one under linux

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜