34 lines
663 B
C
34 lines
663 B
C
#include <stdio.h>
|
|
#include <signal.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <sys/types.h>
|
|
|
|
void handler(int signum)
|
|
{
|
|
if (signum == SIGUSR1)
|
|
{
|
|
FILE *fp;
|
|
fp = fopen("test.txt", "w");
|
|
fprintf(fp, "coucou, je suis bien en vie!\n");
|
|
fclose(fp);
|
|
}
|
|
else if (signum == SIGUSR2)
|
|
{
|
|
exit(EXIT_SUCCESS);
|
|
}
|
|
else
|
|
{
|
|
printf("received signal %d\n", signum);
|
|
}
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
if (signal(SIGUSR1, handler) == SIG_ERR)
|
|
printf("can't catch SIGUSR1\n");
|
|
if (signal(SIGUSR2, handler) == SIG_ERR)
|
|
printf("can't catch SIGUSR2\n");
|
|
for (;;)
|
|
pause();
|
|
} |