Skip to content

Instantly share code, notes, and snippets.

@dulimarta
Last active January 18, 2018 14:28
Show Gist options
  • Save dulimarta/a43defb640bbab2d4f3a to your computer and use it in GitHub Desktop.
Save dulimarta/a43defb640bbab2d4f3a to your computer and use it in GitHub Desktop.
CS452 Lab02 - Sample 3
#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