File descriptors are indeed βinheritedβ during forking, but only with respect to which socket they are connected to, and closing the file descriptor only closes the socket if it is last connected to this socket (or the file if we are dealing with files).
What you usually do is install a socket and then a plug. In the parent process (the one where fork returned a non-zero value), you can continue and close the file descriptor with close(fd) , if you do not, you will end up with file descriptors in the parent process. This is for stream sockets (e.g. TCP), where you have one server socket that listens for connections, and one socket in the established connection. However, you are using UDP, so there really is only one socket, and if you intend to continue using it in the parent process, you will need to figure out how to split it between the parent and child process. Both may continue to use it, but it will be almost random, which reads what and in what order the material is sent. In this case, you usually have some kind of multiplexing process that receives packets and forwards them to the appropriate child element (to some other mechanism, such as pipes or other sockets) based on some message content (in TCP, this is the ip / port source and destination ip / port tuple).
As Matt noted, using shutdown will actually make the socket unusable (usually unacceptable, but you can specify this) for all participants. In TCP, this can cause a FIN packet to be sent, effectively initiating a connection drop, but you can still receive data until the remote end confirms FIN.
source share