Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- int main()
- {
- pid_t idPA;
- pid_t idPB;
- pid_t idPB1;
- pid_t idPB2;
- pid_t idPC;
- idPA = getppid();
- printf("\nProcesso A começou a executar...\n\n");
- printf("\nOla sou o Processo A\n\tA_PID:%5d\tA_PPID:%5d\n", getpid(), idPA);
- idPA = fork();
- if(idPA == 0){
- printf("\nProcesso B começou a executar...\n\n");
- printf("\nOla sou Processo B\n\tB_PID:%5d\tB_PPID:%5d\n", getpid(), getppid());
- idPB=fork();
- if (idPB == 0){
- printf("\nProcesso B.1 começou a executar...\n\n");
- printf("\nOlá sou Processo B.1\n\tB.1_PID:%5d\tB.1_PPID:%5d\n", getpid(), getppid());
- }else{
- idPB=fork();
- if (idPB == 0){
- printf("\nProcesso B.2 começou a executar...\n\n");
- printf("\nOla sou Processo B.2\n\tB.2_PID:%5d\tB.1_PPID:%5d\n", getpid(), getppid());
- }
- }
- else{
- sleep(2);
- printf("\nProcesso A:%5d\n", getpid());
- idPC=fork();
- if (idPC == 0){
- printf("\n");
- }
- }
- sleep(100);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement