Facebook
From filip, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 253
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/types.h>
  4. #include <sys/wait.h>
  5. #include <stdlib.h>
  6.  
  7.  
  8.  
  9. float a=0.0;
  10. float b=0.0;
  11. float c=0.0;
  12.  
  13. int main()
  14. {
  15.  
  16. float a=0.0;
  17. float b=0.0;
  18. float c=0.0;
  19.  
  20. pid_t pid;
  21. pid_t cpid;
  22. int status;
  23.  
  24.  
  25. pid = fork();
  26.  
  27. if (pid == 0)
  28. {
  29.     a=1+1;
  30.     printf("a: (in Proc)= %.2f\n",a);
  31.     sleep(5);
  32.     exit(0);
  33. } else {
  34.     if ((cpid=wait(&status)) == pid)
  35.     {
  36.         printf("Child %d returned\n",pid);
  37.     }
  38.     b=2+2;
  39.     printf("a: (in Parent)=%.2f\n", a);
  40.     printf("b=%.2f\n", b);
  41.     c=a+b;
  42.     printf("c=%.2f\n", c);
  43.  
  44. }
  45.  
  46.  
  47. return 0;
  48.  
  49. }