Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux: how to mark a file descriptor as not inheritable on fork? [duplicate]

Tags:

c

linux

Is it possible to mark a specific file descriptor as not inheritable, or close it, in the child process when fork() is invoked?

like image 887
zer0stimulus Avatar asked Dec 27 '22 17:12

zer0stimulus


1 Answers

No. All file descriptors are inherited in fork. You can set a fd to be closed on exec, however, by using fcntl(fd, F_SETFD, FD_CLOEXEC).

like image 176
bdonlan Avatar answered Jan 04 '23 23:01

bdonlan