Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/unistd.h>
- int main ()
- {
- int p1 = fork();
- int p2 = fork();
- int p3 = fork();
- if (p1 == 0 && p2 > 0 && p3 > 0 )
- {
- printf("Parent A (pid = %d)" , getppid());
- printf(" creates process B (pid = %d)",getpid());
- printf("\n");
- wait(NULL);
- }
- else if (p1 > 0 && p2 == 0 && p3 > 0)
- {
- printf("Parent A (pid = %d)" , getppid());
- printf(" creates process C (pid = %d)",getpid());
- printf("\n");
- wait(NULL);
- }
- else if (p1 > 0 && p2 > 0 && p3 == 0)
- {
- printf("Parent A (pid = %d)" , getppid());
- printf(" creates process D (pid = %d)",getpid());
- printf("\n");
- wait(NULL);
- }
- else if (p1 == 0 && p2 == 0 && p3 > 0)
- {
- printf("Parent B (pid = %d)" , getppid());
- printf(" creates process E (pid = %d)",getpid());
- printf("\n");
- wait(NULL);
- }
- else if (p1 > 0 && p2 == 0 && p3 == 0)
- {
- printf("Parent C (pid = %d)" , getppid());
- printf(" creates process G (pid = %d)",getpid());
- printf("\n");
- wait(NULL);
- }
- else if (p1 == 0 && p2 > 0 && p3 == 0)
- {
- printf("Parent B (pid = %d)" , getppid());
- printf(" creates process F (pid = %d)",getpid());
- printf("\n");
- wait(NULL);
- }
- else if (p1 == 0 && p2 == 0 && p3 == 0)
- {
- printf("Parent E (pid = %d)" , getppid());
- printf(" creates process I (pid = %d)",getpid());
- printf("\n");
- wait(NULL);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement