69 lines
2.1 KiB
C
69 lines
2.1 KiB
C
/**
|
||
* @ Author: JunkJumper
|
||
* @ Link: https://github.com/JunkJumper
|
||
* @ Copyright: Creative Common 4.0 (CC BY 4.0)
|
||
* @ Create Time: 22-10-2020 11:55:28
|
||
* @ Modified by: JunkJumper
|
||
* @ Modified time: 22-10-2020 11:55:53
|
||
*/
|
||
|
||
/**********************************************************/
|
||
/* DUT INFORMATIQUE - M311 - R. CHIGNOLI */
|
||
/* p_fork_signal : Apr<70>s fork, */
|
||
/* - PERE : Affiche son pid et ppid, */
|
||
/* Ignore le signal SIGINT et le montre */
|
||
/* S'arrete <20> la reception du signal SIGUSR1, */
|
||
/* se met en boucle infinie. */
|
||
/* - FILS : Affiche son pid et son ppid, */
|
||
/* Envoie trois signaux SIGINT au pere, */
|
||
/* Attend un signal SIGTERM de l'utilisateur */
|
||
/* Se met en boucle infinie. */
|
||
/* Envoie le signal SIGUSR1 a son pere a */
|
||
/* l'interception du signal SIGTERM puis */
|
||
/* meurt. */
|
||
/**********************************************************/
|
||
# include <stdio.h>
|
||
# include <stdlib.h>
|
||
# include <signal.h>
|
||
# include <unistd.h>
|
||
|
||
void repSIGINT() {
|
||
printf ("\nJ'ignore le signal SIGINT (<Ctrl + \\C>)\n");
|
||
}
|
||
|
||
int main () {
|
||
int res;
|
||
res = fork();
|
||
|
||
if (res < 0){
|
||
printf ("ERREUR FORK\n");
|
||
}
|
||
else {
|
||
if (res == 0)
|
||
{ /************************** FILS ***********************/
|
||
printf("Je suis le fils : ");
|
||
printf("pid : %d\n", getpid());
|
||
printf("ppid : %d\n",getppid());
|
||
for (int i = 0; i < 5; i++)
|
||
{
|
||
kill(getppid(), SIGINT);
|
||
sleep(1);
|
||
}
|
||
|
||
}
|
||
else
|
||
{ /************************** PERE ***********************/
|
||
printf("Je suis le père : ");
|
||
printf("pid : %d\n", getpid());
|
||
printf("ppid : %d\n",getppid());
|
||
|
||
signal(SIGINT, repSIGINT);
|
||
|
||
|
||
}
|
||
}
|
||
for(;;);
|
||
|
||
return 0;
|
||
}
|