Old stuff/ecole_etude_fac_de_pau/licence_3/systeme-d-exploitation/tp3/main.c
(Deskargatu)
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <errno.h>
void sigfct(int n)
{
printf("%d : j ai recu un signal term\n");
}
void kil(int n)
{
printf("%d : j ai recu un signal kill\n");
}
int main(int argc, char** argv)
{
pid_t pid;
pid= fork();
struct sigaction action_term;
struct sigaction action_kill;
if (pid == -1) {
perror("fork error");
exit(-1);
}
else if (pid == 0)
{
// fils
sleep(1);
kill(getppid(),SIGTERM);
sleep(1);
kill(getppid(), SIGUSR1);
}
else
{
// pere
action_term.sa_handler = sigfct;
sigemptyset(&action_term.sa_mask);
if (sigaction(SIGTERM, &action_term, NULL) == -1)
{
perror("sig action term error");
exit(-1);
}
while(1);
}
return 0;
}