Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4. #include <sys/wait.h>
  5.  
  6. int main()
  7. {
  8. int pid,status,t;
  9. int var=2;
  10. printf("\nbefore if -> PID=%d PPID=%d\n",getpid(),getppid());
  11. if ((pid = fork()) < 0)
  12. {
  13. printf("EROARE!!!");
  14. } else if (pid == 0)
  15. {
  16. sleep(3);
  17. printf("if -> fiu? ->PID=%d PPID=%d\n",getpid(),getppid());
  18. printf("\n\tfiu -> var=%d la adresa %p\n",var,&var);
  19. var++;
  20. printf("\n\tfiu -> var=%d la adresa %p\n",var,&var);
  21. } else
  22. {
  23. printf("if -> parinte? ->PID=%d PPID=%d\n",getpid(),getppid());
  24. printf("\n\tparinte -> var=%d la adresa %p\n",var,&var);
  25. t=wait(&status);
  26. if(t==pid)
  27. printf("\nchiled done\n");
  28. printf("\n\tparinte -> var=%d la adresa %p\n",var,&var);
  29. }
  30. printf("after if -> ? ->PID=%d PPID=%d\n",getpid(),getppid());
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement