...
void sighandler(int signum)
{
fprintf(stderr,"Caught signal %d\n",signum);
socket_closer();
exit(0);
}
...
void socket_closer()
{
pid_t process_id = getpid();
struct dirent * pDirent;
DIR * pDir;
char command_string[255];
char buf
I"m trying to find out how to close sockets with a signal handler
function in C without having the socket numbers.
...
#include
void sighandler(int);
void socket_closer(void);
void sighandler(int signum)
{
socket_closer(); // Close any open sockets...
}
int main(int argc,char * argv)
{
The scenario is you have a standard C program that opens sockets. The
sockets are used in an infinite loop that never exits. How do you close
these sockets immediately on premature exit?
There is C atexit(), but the problem is that no arguments can be passed
to that. I don't have the integers