Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <string.h>
- #include <stdlib.h>
- #include <math.h>
- #include <sys/wait.h>
- #include <sys/stat.h>
- double silnia(double);
- int main() {
- int ch1, status1;
- int ch2, status2;
- int ch3, status3;
- int n;
- float eps;
- int fd[2];
- int fdd[2];
- pipe(fd);
- pipe(fdd);
- if (ch1 = fork() == 0) {
- char str[50], wynik[50];
- double X;
- double Eps;
- printf("Podaj wartosci X \r\n");
- scanf("%lf", &X);
- printf("Podaj wartosci Eps \r\n");
- scanf("%lf", &Eps);
- sprintf(wynik, "%lf", Eps);
- sprintf(str, "%lf", X);
- close(fd[0]);
- write(fd[1], str, sizeof(str));
- write(fd[1], wynik, sizeof(wynik));
- exit(0);
- }
- wait(NULL);
- if (ch2 = fork() == 0) {
- waitpid(ch1, &status1, WCONTINUED);
- double X, Eps;
- char str[50], wynik[50];
- close(fd[1]);
- read(fd[0], str, sizeof(str));
- X = atof(str);
- read(fd[0], str, sizeof(str));
- Eps = atof(str);
- printf("X = %f\n", X);
- printf("Eps = %f\n", Eps);
- exit(0);
- }
- wait(NULL);
- if ((ch3 = fork()) == 0) {
- return 0;
- }
- waitpid(ch3, &status3, WCONTINUED);
- return 0;
- }
- double silnia(double param) {
- double wynik = 1, i = 1;
- while (i <= param) {
- wynik *= i;
- i++;
- }
- return wynik;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement