exo4
This commit is contained in:
32
tp/tp3/src/exo4.c
Normal file
32
tp/tp3/src/exo4.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <sys/wait.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
pid_t p;
|
||||
int status;
|
||||
p = fork();
|
||||
assert( p >= 0);
|
||||
|
||||
if ( p == 0){
|
||||
printf("@retour de fork = %d pid = %d ppid = %d\n",p,getpid(),getppid());
|
||||
sleep(4);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
printf("@retour de fork = %d pid = %d ppid = %d\n",p,getpid(),getppid());
|
||||
|
||||
assert( wait(&status) >= 0);
|
||||
|
||||
if (WIFEXITED(status))
|
||||
printf("code retour fils = %d\n",WEXITSTATUS(status));
|
||||
|
||||
execlp("ls","totototo","-l","/",NULL);
|
||||
|
||||
/* code ici */
|
||||
assert(0);
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user