-
Notifications
You must be signed in to change notification settings - Fork 0
/
please.c
35 lines (32 loc) · 1.03 KB
/
please.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* please.cpp
*
* Created on: 2 févr. 2016
* Author: Quincy
*/
#include <stdio.h> /* printf */
#include <stdlib.h> /* system, NULL, EXIT_FAILURE */
#include <unistd.h>
int main (int argc, char* argv[])
{
printf("%s \n", argv[0]);
for(int i=0; i<5; i++)
{
int pid = fork();
int nRet = -1;
if(pid==0)
{
//nRet = execvp(argv[1], argv+1); //This code is useless because the value of nRet is just a copy in child process where father process can not access and not assigned
execvp(argv[1], argv+1); //argv[1] means only the cell value of cell 1, while argv+1 means all the rest value from the pointer +1
}
wait(&nRet); //Note that here the value of nRet is filled by the return code of the child process (where execvp executes)
printf("Terminaison avec résultat: %d \n", nRet);
if (WIFEXITED(nRet))
printf("Terminaison normal: %d\n", WEXITSTATUS(nRet));
else if (WIFSIGNALED(nRet))
printf("Commande tuée par le signal: %d\n", WTERMSIG(nRet));
else
printf("Bizarre return code!\n");
}
return 0;
}