ソケット作成時にSOCK_を使用CLOEXEC設定close-on-exec


マニュアルman socketを参照
 
NAME
       socket - create an endpoint for communication

SYNOPSIS
       #include <sys/types.h>          /* See NOTES */
       #include <sys/socket.h>

       int socket(int domain, int type, int protocol);

 
       Since Linux 2.6.27, the type argument serves a second purpose: in addition to specifying a socket type, it may include the bitwise OR of any of the follow‐
       ing values, to modify the behavior of socket():

       SOCK_NONBLOCK   Set the O_NONBLOCK file status flag on the new open file description.  Using this flag saves extra calls to fcntl(2) to  achieve  the  same
                       result.

       SOCK_CLOEXEC    Set  the  close-on-exec (FD_CLOEXEC) flag on the new file descriptor.  See the description of the O_CLOEXEC flag in open(2) for reasons why
                       this may be useful.

SOcketの作成時にtypeフィールドまたはSOCK_CLOEXEC
 
socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);