This is my code for interrupting a process with a signal.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
int main(void){
void sigint_handler(int sig); /* prototype */
char s[200];
if(signal(SIGINT, sigint_handler) == SIG_ERR){
perror("signal");
exit(1);
}
printf("Enter a string:\n");
if(gets(s) == NULL)
perror("gets");
else
printf("You entered: \"%s\"\n", s);
return 0;
}
void sigint_handler(int sig){
printf("Not this time!\n");
}
Question is how do I capture signal such as SIGINT, SIGKILL, SIGHUP and SIGTERM?
The argument
int sigreceived by yoursigint_handlerfunction is the signal that was caught. Constants defining the values are in<signal.h>. So, for example