A C function that is used to overwrite the PCB signal table so that once a signal is recieved, it will call a given function.
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)signumis the Signal’s number\actis the sigaction structoldactis the previous state of the signal
Sigaction struct
struct sigaction{
void (*sa_handler)(int);
void (*a_sigaction)(int, siginfo_y*, void*);
sigset_t sa_mask;
int sa_flags;
void (*sa_restorer)(void);
}Example
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
void handler(int code){
fprintf(stderr, "Signal %d caught\n", code);
}
int main(){
int i = 0;
struct sigaction newact;
newact.sa_handler = handler;
newact.sa_flags = 0; // default flags
sigemptyset(&newact.sa_mask) ; // block no signals during handler
sigaction(SIGINT, &newact, NULL);
for (;;){
if ((1++ % 50000000) == 0){
fprintf("stderr",".");
}
}
return 0;
}