Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/wait.h>
  5.  
  6. #define NB_FORKS 50000
  7.  
  8. void do_nothing(){
  9. int i;
  10. i=0;
  11. exit(EXIT_SUCCESS);
  12. }
  13.  
  14. int main(int argc, char const *argv[])
  15. {
  16. int pid,j,status;
  17.  
  18.  
  19.  
  20. for (j = 0;j<NB_FORKS; j++){
  21. switch(pid=fork()){
  22. case -1:
  23. perror("fork()");
  24. exit(EXIT_FAILURE);
  25. case 0:
  26. do_nothing();
  27. default:
  28. waitpid(pid,&status,0);
  29. break;
  30. }
  31. }
  32. return EXIT_SUCCESS;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement