ASR31-valarche-2021/Exemples/04-Exec/exoTDGr2.c
2021-09-29 16:51:10 +02:00

28 lines
417 B
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main(int argc, char *argv[]) {
pid_t pid;
if (argc < 2) {
perror("argument pas bon");
exit (0);
}
pid = fork();
if (pid == 0) {
if (execvp(argv[1], &argv[1]) == -1)
/* argv+sizeof(char*) c'est trop grand */
{
perror("dans le exec");
exit (0);
}
} else {
wait(NULL);
}
return EXIT_SUCCESS;
}