Ajout de l'exo 4
This commit is contained in:
parent
0cecb7b410
commit
2fff4e7471
39
TP3/Exo4/exo4.c
Normal file
39
TP3/Exo4/exo4.c
Normal file
@ -0,0 +1,39 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include<stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include<assert.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
int main(int argc,char * argv[])
|
||||
{
|
||||
int status;
|
||||
pid_t p, n;
|
||||
|
||||
|
||||
p = fork();
|
||||
assert(p != -1);
|
||||
|
||||
if (p==0) {
|
||||
printf("Le retour du fork est %d\n", p);
|
||||
printf("Mon PID est %d\n", getpid());
|
||||
printf("Le PID de mon pere est %d\n", getppid());
|
||||
sleep(4);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if (p>0) {
|
||||
sleep(1);
|
||||
printf("\nLe retour du fork est %d\n", p);
|
||||
printf("Mon PID est %d\n", getpid());
|
||||
printf("Le PID de mon pere est %d\n", getppid());
|
||||
n = wait(&status);
|
||||
printf("Le fils %d a termine avec le code %d\n", n, WEXITSTATUS(status));
|
||||
execl("/usr/bin/ps", "ps", "-ef", NULL);
|
||||
exit(0);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user