Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- root@cpc304:~# cat test.c
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <sys/time.h>
- main()
- {
- pid_t pid;
- int rv;
- switch(pid=fork()) {
- case -1:
- perror("fork");
- exit(1);
- case 0:
- printf("child\n");
- sleep(3);
- printf("child done\n");
- sleep(1);
- break;
- default:
- printf("parent\n");
- waitpid(pid, 0, 0);
- printf("finished\n");
- }
- }
- root@cpc304:~# gcc test.c -o test
- root@cpc304:~# ./test
- parent
- child
- child done
- finished
- root@cpc304:~#
Advertisement
Add Comment
Please, Sign In to add comment