Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <pthread.h>
- #include <sys/types.h>
- int main(){
- pid_t pai, filho, avo;
- avo = getpid();
- printf("Processo avo, pid = %d.\nCriando filho...\n", (int)avo);
- pai = fork();
- if(!pai){
- printf("Processo pai, pid = %d.\nFilho de %d.\nCriando filho...\n", (int)getpid(), (int)getppid() );
- filho = fork();
- if(!filho){
- printf("Processo filho, pid = %d.\nFilho de %d \nwe are done!\n", (int)getpid(), (int)getppid() );
- }
- else sleep(1);
- }
- else sleep(2);
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment