|
CS 456 - Systems Programming
Spring 2024
|
Displaying ./code/feb08/exec3.c
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char**argv) {
pid_t child = fork();
if (child == -1) return EXIT_FAILURE;
if (child) { /* I have a child! */
int status;
waitpid(child , &status ,0);
return EXIT_SUCCESS;
} else { /* I am the child */
// Other versions of exec pass in arguments as arrays
// Remember first arg is the program name
// Last arg must be a char pointer to NULL
execl("/bin/cat", "cat","exec3.c", (char *) NULL);
// If we get to this line, something went wrong!
perror("exec failed!");
}
}
|