Facebook
From filip, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 260
  1.  
  2. 5
  3. 6
  4. 7
  5. 8
  6. 9
  7. 10
  8. 11
  9. 12
  10. 13
  11. 14
  12. 15
  13. 16
  14. 17
  15. 18
  16. 19
  17. 20
  18. 21
  19. 22
  20. 23
  21. 24
  22. 25
  23. 26
  24. 27
  25. 28
  26. 29
  27. 30
  28. 31
  29. 32
  30. 33
  31. 34
  32. 35
  33. 36
  34. 37
  35. 38
  36. 39
  37. 40
  38. 41
  39. 42
  40. 43
  41. 44
  42. 45
  43. 46
  44. 47
  45. 48
  46. 49
  47. #include <stdio.h>
  48. #include <unistd.h>
  49. #include <sys/types.h>
  50. #include <sys/wait.h>
  51. #include <stdlib.h>
  52.  
  53.  
  54.  
  55. float a=0.0;
  56. float b=0.0;
  57. float c=0.0;
  58.  
  59. int main()
  60. {
  61.  
  62. float a=0.0;
  63. float b=0.0;
  64. float c=0.0;
  65.  
  66. pid_t pid;
  67. pid_t cpid;
  68. int status;
  69.  
  70.  
  71. pid = fork();
  72.  
  73. if (pid == 0)
  74. {
  75.     a=1+1;
  76.     printf("a: (in Proc)= %.2f\n",a);
  77.     sleep(5);
  78.     exit(0);
  79. } else {
  80.     if ((cpid=wait(&status)) == pid)
  81.     {
  82.         printf("Child %d returned\n",pid);
  83.     }
  84.     b=2+2;
  85.     printf("a: (in Parent)=%.2f\n", a);
  86.     printf("b=%.2f\n", b);
  87.     c=a+b;
  88.     printf("c=%.2f\n", c);
  89.  
  90. }
  91.  
  92.  
  93. return 0;
  94.  
  95. }