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 43 44 45 46 47 48 49 50 51 52
| #include<stdio.h>
#include<signal.h>
#include<string.h>
#include<stdlib.h>
main()
{
pid_t pid;
char rep[80];
pid=fork();
if(pid<0)
{
perror("erreur du processus\n");
}
if(pid==0)
{
while(1){
printf("OPTION\n");
scanf("%s",rep);
sleep(3);
printf("Je suis le fils\n");
if(strcmp(rep,"s"))
{ printf("Le fils va dormir");
kill(pid, SIGSTOP);
}
if(strcmp(rep,"r"))
{ printf("redémarrer fils");
kill(pid, SIGCHLD);
}
if(strcmp(rep,"q"))
{ printf("tuer le fils");
kill(pid, SIGKILL);
}
}
}
if(pid>0)
{
printf("Je suis le père");
printf("(s)---> endormir fils\n");
printf("(r)---> redémarre fils\n");
printf("(q)---> tuer le fils\n");
signal(SIGINT, SIG_DFL);
}
} |
Partager