Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. #include <sys/wait.h>
  2.  
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <stdio.h>
  6. #include <stdbool.h>
  7.  
  8. int main()
  9. {
  10. int i, status;
  11. bool acabat=false;
  12. for (i=0;i<3;i++){
  13.  
  14.     if(fork()!=0) {
  15.         /*    
  16.         pid_t waitpid(pid_t pid, int *status_ptr, int options);
  17.         If pid is greater than 0, waitpid() waits for termination of the specific child whose process ID is equal to pid.
  18.     If pid is equal to zero, waitpid() waits for termination of any child whose process group ID is equal to that of the caller.
  19.     If pid is -1, waitpid() waits for any child process to end.
  20.     If pid is less than -1, waitpid() waits for the termination of any child whose process group ID is equal to the absolute value of pid.
  21.  
  22.     The status_ptr pointer may also be NULL, in which case waitpid() ignores the child's return status.
  23.  
  24.     bitwise inclusive-OR of zero or more of the following flags
  25.  
  26. */
  27.        
  28.         wait(NULL);
  29.        // waitpid(-1,NULL,0);
  30.         printf("i= %d, Proceso padre\n",i);}
  31.     else {
  32.        
  33.         printf("i= %d, Proceso hijo\n", i);
  34.         exit(0);
  35.         }
  36.     }
  37.  
  38. exit(0);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement