#include #include #include #include #include #include #include void clc(){ //pipes int pipe1[2];// PIPE A int pipe2[2];// PIPE B if(pipe(pipe1) == -1) return; if(pipe(pipe2) == -1) return; char buffer[2048]; char buffer2[2048]; //fgets(buffer, 2047, stdin); pid_t pid = fork(); if(pid < 0) return; if (pid == 0){ while(read(pipe1[0],buffer ,2047 )){ int n = atoi(buffer); if(n == -1) exit(0); char buf = n *n; write(pipe2[1], &buf , 1); } } else{ read(pipe2[0], buffer2, 2048); if(strcmp(buffer2, "-1") == 0) { close(pipe1[0]); close(pipe1[1]); close(pipe1[0]); close(pipe1[1]); return; } printf("The Oracle says the square is: %s\n", buffer2); } } int main(){ clc(); }