33 lines
1.1 KiB
C
Executable File
33 lines
1.1 KiB
C
Executable File
/******************************************************/
|
|
/* DUT INFORMATIQUE - M311 - R. CHIGNOLI */
|
|
/* demo_kill_grp_2.c : Utilisation de la routine kill */
|
|
/******************************************************/
|
|
# include <stdio.h>
|
|
# include <signal.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
|
|
int main () {
|
|
int res;
|
|
res = fork ();
|
|
if (res != 0){
|
|
printf ("\nPERE No %d ( GRPID = %d ) : j'attends 3 secondes...\n", getpid(), getpgrp());
|
|
sleep (3);
|
|
printf ("\nPERE No %d ( GRPID = %d ) : ... puis je me suicide par kill\n", getpid(), getpgrp());
|
|
kill (0, SIGKILL);
|
|
printf ("\nPERE No %d ( GRPID = %d ) : ... je suis mort\n", getpid(), getpgrp());
|
|
}
|
|
else
|
|
{
|
|
if (setpgid (0, getpid()) != 0){
|
|
perror ("setgpid"); exit (1);
|
|
}
|
|
printf ("\nFILS No %d ( GRPID = %d ) : nouveau groupe ...\n", getpid(), getpgrp());
|
|
printf ("\nFILS No %d ( GRPID = %d ) : J'attends 5 secondes\n", getpid());
|
|
sleep (5);
|
|
printf ("\nFILS No %d ( GRPID = %d ) : Et je meurs naturellement !\n\n",
|
|
getpid());
|
|
exit (0);
|
|
}
|
|
}
|