Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <sys/wait.h>
- int main()
- {
- int pid,status,t;
- int var=2;
- printf("\nbefore if -> PID=%d PPID=%d\n",getpid(),getppid());
- if ((pid = fork()) < 0)
- {
- printf("EROARE!!!");
- } else if (pid == 0)
- {
- sleep(3);
- printf("if -> fiu? ->PID=%d PPID=%d\n",getpid(),getppid());
- printf("\n\tfiu -> var=%d la adresa %p\n",var,&var);
- var++;
- printf("\n\tfiu -> var=%d la adresa %p\n",var,&var);
- } else
- {
- printf("if -> parinte? ->PID=%d PPID=%d\n",getpid(),getppid());
- printf("\n\tparinte -> var=%d la adresa %p\n",var,&var);
- t=wait(&status);
- if(t==pid)
- printf("\nchiled done\n");
- printf("\n\tparinte -> var=%d la adresa %p\n",var,&var);
- }
- printf("after if -> ? ->PID=%d PPID=%d\n",getpid(),getppid());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement