From 9a472fdd081234fa9e822247eb10a3ed967310fd Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 16 Apr 2026 23:19:25 +0200 Subject: [PATCH] double_pipe.c --- .gitignore | 1 + AnimalProcessing/Fundamentals/wait.c | 6 +- AnimalProcessing/Proficiencies/autre.c | 63 ----------------- AnimalProcessing/Proficiencies/double_pipe.c | 67 ++++++++++++------- AnimalProcessing/Proficiencies/dup.c | 5 +- AnimalProcessing/Proficiencies/project.c | 10 +-- AnimalProcessing/Proficiencies/test | Bin 16360 -> 0 bytes 7 files changed, 54 insertions(+), 98 deletions(-) delete mode 100644 AnimalProcessing/Proficiencies/autre.c delete mode 100755 AnimalProcessing/Proficiencies/test diff --git a/.gitignore b/.gitignore index 888e1f5..3886d61 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.obj *.out +*.html .idea/ *~ *.DotSettings.user diff --git a/AnimalProcessing/Fundamentals/wait.c b/AnimalProcessing/Fundamentals/wait.c index e54b387..8e72937 100644 --- a/AnimalProcessing/Fundamentals/wait.c +++ b/AnimalProcessing/Fundamentals/wait.c @@ -22,11 +22,9 @@ int wait_child(int x){ if(pid < 0) return -1; // Child - else if (pid == 0) { - - if (x < 0) exit(-1); + else if (pid == 0) { - exit(fibo(x)); + exit(fibo(x)); } // Daddy diff --git a/AnimalProcessing/Proficiencies/autre.c b/AnimalProcessing/Proficiencies/autre.c deleted file mode 100644 index 121f141..0000000 --- a/AnimalProcessing/Proficiencies/autre.c +++ /dev/null @@ -1,63 +0,0 @@ -#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(); - - -} diff --git a/AnimalProcessing/Proficiencies/double_pipe.c b/AnimalProcessing/Proficiencies/double_pipe.c index 98af798..5deba32 100644 --- a/AnimalProcessing/Proficiencies/double_pipe.c +++ b/AnimalProcessing/Proficiencies/double_pipe.c @@ -14,56 +14,73 @@ ___( o)> Coic Coic */ -void clc(){ +int main(){ - int n = 0; + //pipes int pipe1[2]; int pipe2[2]; + if(pipe(pipe2) == -1) return 1; + if(pipe(pipe1) == -1) return 1; + 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; + if(pid < 0) return 1; //Child if(pid == 0) { - while(1){ + close(pipe1[1]); + close(pipe2[0]); - if(pipe1[0]){ - pipe2[1] = n* n; - exit(0); - } + int n; + + while(read(pipe1[0], &n, sizeof(int))){ + + int rslt = n * n; + write(pipe2[1], &rslt, sizeof(int)); } + + close(pipe1[0]); + close(pipe2[1]); + 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;} + close(pipe1[0]); + close(pipe2[1]); - pipe1[1] = n; + int nbr = 0; + while(fgets(buffer, 2047, stdin)){ + + nbr = atoi(buffer); + + if(nbr == -1) break; + + write(pipe1[1], &nbr, sizeof(int)); + + int rslt; + read(pipe2[0], &rslt, sizeof(int)); + printf("The Oracle says the square is: %i\n", rslt); + } + close(pipe1[1]); + close(pipe2[0]); + wait(NULL); //on attends le Child - printf("The Oracle says the square is: %i\n", pipe2[0]); + } } -int main() { +//int main() { - clc(); +// clc(); /* //[0] -> lecture | [1]-> ecriture @@ -105,4 +122,4 @@ int main() { }*/ -} +//} diff --git a/AnimalProcessing/Proficiencies/dup.c b/AnimalProcessing/Proficiencies/dup.c index 3a7fb6f..a695ab5 100644 --- a/AnimalProcessing/Proficiencies/dup.c +++ b/AnimalProcessing/Proficiencies/dup.c @@ -20,11 +20,12 @@ int duper(char **argv, char *output){ //int fd[2]; //pipe(fd); - + if(!argv || !*argv || !output) return 1; + int wstatus; pid_t pid = fork(); - if(pid < 0) return -1; + if(pid < 0) return 1; //Child else if (pid == 0){ diff --git a/AnimalProcessing/Proficiencies/project.c b/AnimalProcessing/Proficiencies/project.c index b029511..9135f6b 100644 --- a/AnimalProcessing/Proficiencies/project.c +++ b/AnimalProcessing/Proficiencies/project.c @@ -60,6 +60,8 @@ char** split(char* line){ int exec_cmd(char** args){ + if(!args || !*args) return -1; + int wstatus; pid_t pid = fork(); @@ -85,7 +87,7 @@ int exec_cmd(char** args){ if(waitpid(pid, &wstatus, 0) == -1) return -1; if( WIFEXITED(wstatus)){ - if(WEXITSTATUS(wstatus) == 255) return 1; + if(WEXITSTATUS(wstatus) == 255) return -1; else return WEXITSTATUS(wstatus); }} return 0; @@ -135,7 +137,7 @@ int execution_loop(){ //execution du run via le child else if (strcmp(args[0], "run") == 0){ //printf("test\n"); - last_code = exec_cmd(args); + if(args[1]) last_code = exec_cmd(args); } //interrogation du last_code @@ -158,11 +160,11 @@ int is_terminal() { return isatty(STDIN_FILENO) && isatty(STDOUT_FILENO); } +/* int main() { printf("\n Code de fin : %i\n",execution_loop()); } - - +*/ /* int main(){ diff --git a/AnimalProcessing/Proficiencies/test b/AnimalProcessing/Proficiencies/test deleted file mode 100755 index 2c08d6b34ca26bc72f964aa54ca0d81c963c8133..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16360 zcmeHOeQX>@6`ymG#{G)jw4q5_noCIAq{U}Db`p~kdWmCa9h}B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