开发者

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

开发者 https://www.devze.com 2023-04-12 16:29 出处:网络
This question has been asked several times here, but I can\'t find answer开发者_如何学JAVA for the following situation:

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

精彩评论

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