/* http://vip.cs.utsa.edu/usp/ dr.robbins utsa computer science "unix systems programming" */
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(void) {
int x;
pid_t pid;
x = 0;
printf("before fork: I am process %ld and my x is %d\n", (long)getpid(), x);
pid = fork();
x = 1;
if (pid > 0) {
printf("after fork: I am process %ld and my x is %d\n", (long)getpid(), x);
wait(pid);
}
if (pid == 0) {
printf("I am process %ld and my x is %d\n", (long)getpid(), x);
sleep(10);
}
return 0;
}
return to top