Guest User

Untitled

a guest
Aug 21st, 2015
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. root@cpc304:~# cat test.c
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <errno.h>
  5. #include <unistd.h>
  6. #include <sys/types.h>
  7. #include <sys/wait.h>
  8. #include <sys/time.h>
  9.  
  10. main()
  11. {
  12. pid_t pid;
  13. int rv;
  14. switch(pid=fork()) {
  15. case -1:
  16. perror("fork");
  17. exit(1);
  18. case 0:
  19. printf("child\n");
  20. sleep(3);
  21. printf("child done\n");
  22. sleep(1);
  23. break;
  24. default:
  25. printf("parent\n");
  26. waitpid(pid, 0, 0);
  27. printf("finished\n");
  28. }
  29. }
  30. root@cpc304:~# gcc test.c -o test
  31. root@cpc304:~# ./test
  32. parent
  33. child
  34. child done
  35. finished
  36. root@cpc304:~#
Advertisement
Add Comment
Please, Sign In to add comment