Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. #include <unistd.h>
  5. #include <pthread.h>
  6. #include <signal.h>
  7. #include <string.h>
  8. #include <fcntl.h>
  9. #include<sys/mman.h>
  10. #include<sys/ipc.h>
  11. #include<sys/shm.h>
  12.  
  13.  
  14. int main(int ac,char** av) {
  15. int a = 0, b = 1, c = 2, i, r[5];
  16. for(i = 0; i < 5; i++) {
  17. if( (r[i] = fork()) ) {
  18. a = getpid();
  19. srandom(a);
  20. b = random()%10;
  21. sleep(b);
  22. exit(a+b);
  23. }
  24. }
  25. i = 0;
  26. while(-1 != waitpid(r[i], &c, 0)) {
  27. printf("%d %d %d %d \n", a, b, r[i], WEXITSTATUS(c));
  28. i++;
  29. }
  30.  
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement