Exec
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main() {
pid_t pid;
switch (pid = fork()) {
case -1: // Fork failed
perror("Fork failed");
exit(-1);
case 0: // Child process
printf("Child process\n");
execl("/bin/date", "date", NULL); // Execute the "date" command
exit(0);
default: // Parent process
wait(NULL); // Wait for the child to terminate
printf("Child Terminated\n");
exit(0);
}
}
Comments
Post a Comment