+ exemple ipc/signal
This commit is contained in:
@@ -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
30
code/get-signal.c
Normal 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user