Figure 6. Use of asynchronous notification of I/O requests.

#include <fcntl.h>
... 
int io_handler(); 
... 
signal(SIGIO, io_handler);

/* Set the process receiving SIGIO/SIGURG signals to us */

if (fcntl(s, F_SETOWN, getpid()) < 0) { 
     perror("fcntl F_SETOWN"); 
     exit(1); 
}

/* Allow receipt of asynchronous I/O signals */

if (fcntl(s, F_SETFL, FASYNC) < 0) { 
     perror("fcntl F_SETFL, FASYNC"); 
     exit(1); 
}