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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| # include <stdio.h>
# include <unistd.h>
# include <sys/types.h>
# include <sys/wait.h>
# include <assert.h>
# include <stdlib.h>
int spawn (char *fichier, char *arg[]) {
int t;
t = fork();
if ( t < 0 ) {
perror("fork");
exit(1);
}
if ( t == 0 ) {
execv(fichier, arg);
perror("execv");
exit(1);
}
return t;
}
int main()
{ int t, tt, etat;
char * ter_argumen[] = {"true", "echo réussi\n", 0,};
t = spawn("./my-if", ter_argumen);
if (t<0){
perror("echo");
return 1;
}
tt = wait(&etat);
assert(tt == t);
if (etat != 0){
perror("exec my-if");
return 1;
}
return 1;
} |