Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <fcntl.h>
- #include <stdio.h>
- void main(void)
- {
- int pid2, pid3, st; /* process 1 */
- printf("Process 1, pid = %d:\n", getpid());
- pid2 = fork();
- if (pid2 == 0) /* process 2 */
- {
- printf("Process 2, pid = %d:\n", getpid());
- pid3 = fork();
- if (pid3 == 0) /* process 3 */
- {
- printf("Process 3, pid = %d:\n", getpid());
- sleep(2);
- printf("Process 3: end\n");
- } /* process 2 */
- if (pid3 < 0) printf("Cann't create process 3: error %d\n", pid3);
- wait(&st);
- printf("Process 2: end\n");
- }
- else /* process 1 */
- { if (pid2 < 0) printf("Cann't create process 2: error %d\n", pid2);
- wait(&st);
- printf("Process 1: end\n");
- }
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement