37 lines
604 B
C
37 lines
604 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
|
|
pid_t Fork(void) {
|
|
pid_t pid;
|
|
|
|
if ((pid = fork()) < 0) {
|
|
fprintf(stderr, "Fork Error: %s\n", strerror(errno));
|
|
exit(1);
|
|
}
|
|
|
|
return pid;
|
|
}
|
|
|
|
int main() {
|
|
pid_t pid;
|
|
int x = 1;
|
|
pid = Fork();
|
|
if (pid == 0) {
|
|
// Child
|
|
printf("Child: x = %d\n", ++x);
|
|
//getchar();
|
|
exit(0);
|
|
}
|
|
|
|
//wait(NULL); No Wait => Topo Sort
|
|
|
|
printf("Parent: x = %d\n", ++x);
|
|
getchar();
|
|
exit(0);
|
|
}
|