You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
919 B
39 lines
919 B
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <time.h>
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
pid_t pid;
|
|
int time = 2;
|
|
status = 0;
|
|
|
|
switch(pid=fork()) {
|
|
|
|
case -1 : // Oups !!! fork n'a pas marché !
|
|
perror("fork"); exit(errno);
|
|
|
|
case 0 : // Code du fils
|
|
printf("je suis le fils de %d\n", getppid());
|
|
for(int i = 0; i <= 9; ++i) {
|
|
printf("%d \n", i); //\n ==> signale pour dire qu'il faut afficher à l'écran
|
|
usleep(500000);
|
|
}
|
|
system("ps -f");
|
|
exit(2);
|
|
|
|
default : // Code du père
|
|
pid = wait(&status);
|
|
printf("Mon fils m'a renvoyé le code de retour %d\n", WEXITSTATUS(status);
|
|
printf("Fin du processus père de pid %d.\n", getpid());
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|
|
}
|