How should I close a socket in a signal handler?
I'm writing a very simple server that loops forever until Ctrl-C is pressed. I'd like to have the signal handler for ctrl-c close the open sockets and shut down the server, but I don't know what the scope is for a signal handler, and I don't like the idea of declaring the socket(s) I would need to close to be global. Can someone offer suggestions? Is there some standard way to do this? Well, since you have signal handlers, I'm going to assume you're on a Unix variant. If so: A socket is identified to the kernel by the file number, which is an int. See socket(2) . That int is valid for your