Advertisement
SIKER_98

czas

Dec 15th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <fcntl.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7. #include <sys/wait.h>
  8. #include <sys/stat.h>
  9.  
  10. double silnia(double);
  11.  
  12.  
  13. int main() {
  14. int ch1, status1;
  15. int ch2, status2;
  16. int ch3, status3;
  17. int n;
  18. float eps;
  19. int fd[2];
  20. int fdd[2];
  21.  
  22. pipe(fd);
  23. pipe(fdd);
  24.  
  25.  
  26. if (ch1 = fork() == 0) {
  27. char str[50], wynik[50];
  28. double X;
  29. double Eps;
  30.  
  31.  
  32. printf("Podaj wartosci X \r\n");
  33. scanf("%lf", &X);
  34. printf("Podaj wartosci Eps \r\n");
  35. scanf("%lf", &Eps);
  36.  
  37.  
  38. sprintf(wynik, "%lf", Eps);
  39. sprintf(str, "%lf", X);
  40. close(fd[0]);
  41. write(fd[1], str, sizeof(str));
  42. write(fd[1], wynik, sizeof(wynik));
  43. exit(0);
  44. }
  45. wait(NULL);
  46. if (ch2 = fork() == 0) {
  47. waitpid(ch1, &status1, WCONTINUED);
  48. double X, Eps;
  49. char str[50], wynik[50];
  50. close(fd[1]);
  51. read(fd[0], str, sizeof(str));
  52. X = atof(str);
  53. read(fd[0], str, sizeof(str));
  54. Eps = atof(str);
  55.  
  56. printf("X = %f\n", X);
  57. printf("Eps = %f\n", Eps);
  58.  
  59. exit(0);
  60. }
  61. wait(NULL);
  62. if ((ch3 = fork()) == 0) {
  63.  
  64. return 0;
  65. }
  66.  
  67. waitpid(ch3, &status3, WCONTINUED);
  68.  
  69.  
  70. return 0;
  71.  
  72. }
  73.  
  74. double silnia(double param) {
  75. double wynik = 1, i = 1;
  76. while (i <= param) {
  77. wynik *= i;
  78. i++;
  79. }
  80. return wynik;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement