Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <stdlib.h>
- int main() {
- pid_t pid1, pid2, pid3, pid4;
- printf("Parent PID: %d\n", getpid());
- pid1 = fork();
- if (pid1 == 0) {
- printf("Child 1 PID: %d, Parent PID: %d\n", getpid(), getppid());
- pid2 = fork();
- if (pid2 == 0) {
- printf("Child 2 PID: %d, Parent PID: %d\n", getpid(), getppid());
- }
- else {
- pid3 = fork();
- if (pid3 == 0) {
- printf("Child 3 PID: %d, Parent PID: %d\n", getpid(), getppid());
- }
- else {
- pid4 = fork();
- if (pid4 == 0) {
- printf("Child 4 PID: %d, Parent PID: %d\n", getpid(), getppid());
- }
- else {
- wait(0);
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement