Problem
The man pages for the signal(S) and sigaction(S) system calls
show how they are defined but not how to use them. Consequently
it is difficult to use the correct syntax in a C program. Solution
These two sample pieces of code show the correct syntax for the signal(S) and sigaction(S) system calls:
#include<stdio.h>
#include<errno.h>
#include<signal.h>
void
myfunc( int sig )
{
do something ...
}
main( int argc, char *argv[])
{
if (signal(SIGINT, (void(*)()) myfunc) == SIG_ERR){
perror("SIGNAL SIGINT: ");
exit(-1);
}
}
-----------------------------------------------------------------
#include<stdio.h>
#include<signal.h>
#include<errno.h>void myfunc( int sig ) { do something when Del key is pressed }
main( int argc, char *argv[])
{
struct sigaction nact, /* new action */
oact; /* old action */nact.sa_handler = (void(*)()) myfunc;
nact.sa_mask = 0;
nact.sa_flags = SA_NOCLDSTOP; if (sigaction( SIGINT, &nact, &oact )!= 0) {
perror("Sigaction: SIGINT ");
exit(errno);
}
}