What does the FD_CLOEXEC fcntl() flag do?

Like so:

if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
...

Though I’ve read man fcntl, I can’t figure out what it does.

What does beforefieldinit flag do?

What does beforefieldinit flag do? When I look into the IL of my class I see this flag but I don’t know what this flag is actually doing?

linux fcntl – unsetting flag

How do i unset a already set flag using fcntl? For e.g. I can set the socket to nonblocking mode using fcntl(sockfd, F_SETFL, flags | O_NONBLOCK) Now, i want to unset the O_NONBLOCK flag. I tried fc

What does ‘op’ mean in python’s fcntl.ioctl?

According to the fcntl documentation the usage of fcntl.ioctl is as follows: fcntl.ioctl(fd, op[, arg[, mutate_flag]]) with op defined as The operation is defined by op and is operating system depen

What does the fpermissive flag do?

I’m just wondering what the -fpermissive flag do in g++ compiler? I am getting: error: taking address of temporary [-fpermissive] which I can solve by giving -fpermissive flag to the compiler. Thanks

What does JVM flag CMSClassUnloadingEnabled actually do?

I cannot for the life of me find a definition of what the Java VM flag CMSClassUnloadingEnabled actually does, other than some very fuzzy high-level definitions such as gets rid of your PermGen probl

What does the -PIPE flag do in a kill command

A KornShell (ksh) script (scriptC.ksh) is called indirectly by scriptA.ksh (scriptA.ksh calls scriptB.ksh which calls scriptC.ksh). scriptC.ksh: kill -PIPE ${PPID} What does the -PIPE flag do here? I

What does the g++ -D flag do?

I am looking at a CFLAGS of – CFLAGS=-g -w -D LINUX -O3 -fpermissive in a Makefile. What does the -D flag do? I see on the man page that -D name Predefine name as a macro, with definition 1. but I

What does the -ObjC linker flag do?

Simple question. Might have been answered before but was unable to get a exact answer. Right now, I have an app that works with and without the linker flag. However, without the linker flag, I get a v

MACOSX (BSD) equivalent for F_NOTIFY flag for fcntl() function

Does anybody know equivalent for F_NOTIFY flag for fcntl function in a BSD based system? This flag allows you to receive notifications about file events (for example file opened, file closed, bytes wr

What does regex’ flag ‘y’ do?

MDN says: To perform a sticky search, that matches starting at the current position in the target string, use the y flag. I don’t quite understand it.

Answers

It sets the close-on-exec flag for the file descriptor, which causes the file descriptor to be automatically (and atomically) closed when any of the exec-family functions succeed.

It also tests the return value to see if the operation failed, which is rather useless if the file descriptor is valid, since there is no condition under which this operation should fail on a valid file descriptor.

It marks the file descriptor so that it will be close()d automatically when the process or any children it fork()s calls one of the exec*() family of functions. This is useful to keep from leaking your file descriptors to random programs run by e.g. system().

It will allow the OS to automatically close the file descriptor if any other process to execute the file you open(the file your fd is referring to). This is more useful when you writing any scripts and in multi-threaded programming environments.