+ exemple ipc/signal

This commit is contained in:
tth
2021-08-18 09:49:28 +02:00
parent b56f05cd3c
commit 646e3aacc9
4 changed files with 72 additions and 11 deletions

View File

@@ -19,3 +19,5 @@ arguments: arguments.c Makefile
no-op: no-op.c Makefile
gcc -Wall $< -o $@
get-signal: get-signal.c Makefile
gcc -Wall $< -o $@

30
code/get-signal.c Normal file
View File

@@ -0,0 +1,30 @@
/* get-signal.c */
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
volatile int drapeau;
void attraper(int value)
{
drapeau = 1;
}
int main(int argc, char *argv[])
{
int foo;
printf("kill me, my pid is %d\n", getpid());
signal(SIGUSR1, attraper);
for (foo=0; foo<1337; foo++) {
if (drapeau) {
printf("count is %d\n", foo);
drapeau = 0;
}
sleep(1); /* simulate heavy computing */
}
return 0;
}