Example for chapter on UNIX signals

This commit is contained in:
Fabio Scotto di Santolo
2025-08-22 14:22:01 +02:00
parent 99cbf7d4fb
commit 035027ad06
5 changed files with 200 additions and 0 deletions

20
chp10/simple_catch.c Normal file
View File

@@ -0,0 +1,20 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void catch_sighup(int);
int main(void)
{
signal(SIGHUP, catch_sighup);
printf("Hi, I'm a process with PID %d\n", getpid());
sleep(1000);
return EXIT_SUCCESS;
}
void catch_sighup(int sig)
{
printf("Catch signal SIGHUP\n");
exit(EXIT_SUCCESS);
}