开发者

SetHandleInformation() Linux equivalent

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?


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜