This repository has been archived on 2026-05-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
prog-104-p-04-2030/AnimalProcessing/Proficiencies/double_pipe.c
T
2026-04-16 18:56:01 +02:00

109 lines
1.7 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/types.h>
#include <err.h>
/*
__
___( o)>
\ <_. )
`---'
Coic Coic
*/
void clc(){
int n = 0;
int pipe1[2];
int pipe2[2];
char buffer[2048];
if(pipe(pipe2) == -1) return;
if(pipe(pipe1) == -1) return;
fgets(buffer, 2047, stdin);
n = atoi(buffer);
pipe1[1] = n;
pid_t pid = fork();
if(pid < 0) return;
//Child
if(pid == 0) {
while(1){
if(pipe1[0]){
pipe2[1] = n* n;
exit(0);
}
}
}
//Teacher ? WTF what are you doing with my uncle ? Why do you have an eggplant in your right hand and a riding whip in your left hand ? WTF is going on here
else {
if(n == -1) {
close(pipe1[0]);
close(pipe2[1]);
return;}
pipe1[1] = n;
wait(NULL); //on attends le Child
printf("The Oracle says the square is: %i\n", pipe2[0]);
}
}
int main() {
clc();
/*
//[0] -> lecture | [1]-> ecriture
int pipe1[2];
int pipe2[2];
if(pipe(pipe1) == -1) return 1;
if(pipe(pipe2) == -1) return 1;
pid_t pid = fork();
if(pid < 0) return 1;
//Child
else if (pid == 0) {
}
//Teacher ? WTF what are you doing here ?
else{
close(pipe1[0]);
close(pipe2[1]);
char buffer[2048];
fgets(buffer, 2047, stdin);
if(strcmp(buffer, "-1") == 0){
close(pipe2[0]);
close(pipe1[1]);
return 1;
}
pipe1[1] = buffer;
}*/
}