Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/wait.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <stdbool.h>
- int main()
- {
- int i, status;
- bool acabat=false;
- for (i=0;i<3;i++){
- if(fork()!=0) {
- /*
- pid_t waitpid(pid_t pid, int *status_ptr, int options);
- If pid is greater than 0, waitpid() waits for termination of the specific child whose process ID is equal to pid.
- If pid is equal to zero, waitpid() waits for termination of any child whose process group ID is equal to that of the caller.
- If pid is -1, waitpid() waits for any child process to end.
- 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.
- The status_ptr pointer may also be NULL, in which case waitpid() ignores the child's return status.
- bitwise inclusive-OR of zero or more of the following flags
- */
- wait(NULL);
- // waitpid(-1,NULL,0);
- printf("i= %d, Proceso padre\n",i);}
- else {
- printf("i= %d, Proceso hijo\n", i);
- exit(0);
- }
- }
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement