-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsigusr.c
More file actions
42 lines (35 loc) · 732 Bytes
/
sigusr.c
File metadata and controls
42 lines (35 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
volatile sig_atomic_t n_sigusr1 = 0;
static void sig_handler(int);
int main(int argc, char *argv[])
{
if (signal(SIGUSR1, sig_handler) == SIG_ERR)
{
perror("signal");
exit(EXIT_FAILURE);
}
while ((n_sigusr1) < 5)
{
// vide
}
printf("Fin du processus\n");
printf("Reçu %d SIGUSR1\n", n_sigusr1);
return (EXIT_SUCCESS);
}
static void sig_handler(int signum)
{
if (signum == SIGUSR1)
{
n_sigusr1++;
}
else
{
char *msg = "Reçu signal inattendu\n";
write(STDERR_FILENO, msg, strlen(msg));
_exit(EXIT_FAILURE);
}
}