csci4061/lab02-code/fork-exec1.c
Michael Zhang 041f660ccd
f
2018-01-29 17:28:37 -06:00

24 lines
469 B
C

#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
int main(void){
char *child_argv[] = {"--", "derpalerp",NULL};
char *child_cmd = "cowsay";
printf("Running command '%s'\n",child_cmd);
printf("------------------\n");
pid_t child = fork();
if (child == 0) { // child
execvp(child_cmd,child_argv);
} else {
waitpid(child, 0, 0);
printf("------------------\n");
printf("Finished\n");
}
return 0;
}