Last active
January 18, 2018 14:28
-
-
Save dulimarta/a43defb640bbab2d4f3a to your computer and use it in GitHub Desktop.
CS452 Lab02 - Sample 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/types.h> | |
#include <sys/wait.h> | |
#include <unistd.h> | |
int main() | |
{ | |
// use these variables | |
pid_t pid, child; | |
int status; | |
if ((pid = fork()) < 0) { | |
perror("fork failure"); | |
exit(1); | |
} | |
else if (pid == 0) { | |
printf("I am child PID %ld\n", (long) getpid()); | |
/* insert an appropriate form of the exit() function here */ | |
} | |
else { | |
/* insert an appropriate form of the wait() system call here */ | |
printf("Child PID %ld terminated with return status %d\n", (long) child, WEXITSTATUS(status)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment