简体   繁体   中英

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 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 eg http://www.enderunix.org/docs/eng/daemon.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM