Jeremiah_

SO P&T - 1

Sep 30th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <pthread.h>
  5. #include <sys/types.h>
  6.  
  7.  
  8. int main(){
  9.  
  10.     pid_t pai, filho, avo;
  11.    
  12.     avo = getpid();
  13.  
  14.     printf("Processo avo, pid = %d.\nCriando filho...\n", (int)avo);
  15.    
  16.     pai = fork();
  17.  
  18.     if(!pai){
  19.         printf("Processo pai, pid = %d.\nFilho de %d.\nCriando filho...\n", (int)getpid(), (int)getppid() );
  20.         filho = fork();
  21.        
  22.         if(!filho){
  23.             printf("Processo filho, pid = %d.\nFilho de %d \nwe are done!\n", (int)getpid(), (int)getppid() );    
  24.         }
  25.         else sleep(1);        
  26.     }
  27.     else sleep(2);
  28.    
  29.     exit(0);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment