Advertisement
piffy

Fork-exec (orphan)

Aug 30th, 2014
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stddef.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <sys/types.h>
  6. #include <sys/wait.h>        
  7. int main () {
  8. int p;
  9. printf("Pid del processo padre: %d\n", getpid());
  10. p=fork();
  11. if(p==0) {  printf("Il pid del figlio e' %d , quello del padre e' %d\n", getpid(), getppid());
  12.          sleep(10);
  13.         printf("Termine del processo figlio (%d). Il pid del padre ** ADESSO ** e' %d\n", getpid(), getppid());
  14.          return 0;
  15. }
  16. else     {  sleep (5);
  17.         printf("\nProcess genitore (%d) terminato \n", getpid());
  18.          return 0; }  
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement