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 2c08d6b..0000000 Binary files a/AnimalProcessing/Proficiencies/test and /dev/null differ