Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <sys/wait.h>
  6. #include <sys/types.h>
  7. #include <errno.h>
  8.  
  9. int main()
  10. {
  11. pid_t pid;
  12. /* wypisuje ID procesu */
  13. printf("Moj PID = %d\n", getpid());
  14. /* tworzy nowy proces */
  15. switch(pid = fork())
  16. {
  17. case -1: /* blad */
  18. printf("Error in fork = %d %s\n", errno, strerror(errno));
  19. case 0: /* proces potomny */
  20. {
  21. printf("Jestem procesem potomnym. Moj PID = %d\n", getpid());
  22. printf("Jestem procesem potomnym. Wartosc przekazana przez fork() = %d\n", pid);
  23. return 0;
  24. }
  25. default: /* proces macierzysty */
  26. {
  27. printf("Jestem procesem macierzystym. Moj PID = %d\n", getpid());
  28. printf("Jestem procesem macirzysytm. Wartosc przekazana przez fork = %d\n", pid);
  29. }
  30. /* czeka na zakonczenie procesu potomnego */
  31. /* aby zobaczyc ZOMBI - sleep */
  32. // sleep(10);
  33. if(wait(0) == -1)
  34. {
  35. printf("Error in wait = %d %s\n", errno, strerror(errno));
  36. return 0;
  37. }
  38. } // switch
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement