Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/wait.h>
  6.  
  7. int main() {
  8. int n;
  9. pid_t pid1 = fork();
  10. if (pid1==0){
  11. printf("Proces potomny %d\n",getpid());
  12. printf("podaj liczbe: ");
  13. scanf("%d", &n);
  14.  
  15. for(int i = 0; i < n; i++){
  16. pid_t pid = fork();
  17. if(pid==0){
  18. printf("proces potomny potomka: %d %d \n", getpid(), getppid());
  19.  
  20. exit(1);
  21. } else if(pid < 0){
  22.  
  23. printf("ERROR");
  24. exit(1);
  25. }
  26.  
  27. else{
  28. wait(NULL);
  29. }
  30. }
  31.  
  32. }
  33. else if(pid1 < 0){
  34.  
  35. printf("ERROR");
  36. exit(1);
  37. }
  38. else
  39. {
  40. printf("Proces rodzicielski %d\n",getpid());
  41. wait(NULL);
  42.  
  43. }
  44. return EXIT_SUCCESS;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement