Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use O_CLOEXEC when I open file in Linux?

Tags:

People also ask

What is O_cloexec?

O_CLOEXEC (Since Linux 2.6. 23) Enable the close-on-exec flag for the new file descriptor. Specifying this flag permits a program to avoid additional fcntl(2) F_SETFD operations to set the FD_CLOEXEC flag.

How to open file descriptor in linux?

On Linux, the set of file descriptors open in a process can be accessed under the path /proc/PID/fd/ , where PID is the process identifier. File descriptor /proc/PID/fd/0 is stdin , /proc/PID/fd/1 is stdout , and /proc/PID/fd/2 is stderr .

What is an open file description?

The term open file description is the one used by POSIX to refer to the entries in the system-wide table of open files. In other contexts, this object is variously also called an "open file object", a "file handle", an "open file table entry", or—in kernel-developer parlance—a struct file.


My process forks several times, and each time the child will exec - means I want it to run some other program.

In the main process I open a file descriptor with the open() syscall.

Would it be correct to give it a flag O_CLOEXEC so the new program that I run with exec() wouldn't has the fd resource?