tags:

views:

49

answers:

1

Hi,

for a TCP Server Class I need a Linux function, which does what SetHandleInformation(, HANDLE_FLAG_INHERIT, 0) do under Windows. I've already searched the web after a Linux equivalent, but I didn't find anything useful. The only reason I need that function is to make the socket handle inheritable to child processes. So in case there is no Linux SetHandleInformation(), is there another way to do this under Linux?

+1  A: 

File descriptors in Linux are inherited by child processes by default. To alter that, you use the fcntl() function. The following invocation will set the "close-on-exec" flag on the socket, which is equivalent to making it non-inheritable.

fcntl(socket, F_SETFD, FD_CLOEXEC);

To do the opposite (make the socket inheritable, the default) is just:

fcntl(socket, F_SETFD, 0);
caf