Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4. #include <sys/wait.h>
  5. #include <stdlib.h>
  6.  
  7. void dziecko(int a);
  8.  
  9. int main (int argc, char *argv[])
  10. {
  11. int status;
  12. int pid;
  13. pid_t potomek;
  14. int i, j;
  15.  
  16. for(i = 1; i < atoi(argv[1])+1; i++) {
  17. potomek = fork ();
  18. if (potomek == 0) {
  19. pid = getpid();
  20. for(j = 0; j < 4; j++)
  21. printf("Potomek: %d PID: %d PPID: %d\n", i, getpid(), getppid());
  22. sleep(i);
  23. exit(0);
  24. }
  25. }
  26.  
  27. while ((pid = wait(&status)) > 0)
  28. printf("\nPID: %d, status: %d\n", pid, status);
  29.  
  30. return 0;
  31. }
  32.  
  33. void dziecko(int a)
  34. {
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement