From 16fee12b7d6d94854fd2ecc51134023f6e3aba42 Mon Sep 17 00:00:00 2001 From: ngwalang Date: Fri, 22 Sep 2023 16:16:04 +0200 Subject: [PATCH] TP333333 --- SCR3.1/TP3/ex5.c | 35 +++++++++++++++++++++++++++++++++++ SCR3.1/TP3/fils.c | 37 +++++++++++++++++++++++++++++++++++++ SCR3.1/TP3/tp3-reponses.txt | 2 +- 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 SCR3.1/TP3/ex5.c create mode 100644 SCR3.1/TP3/fils.c diff --git a/SCR3.1/TP3/ex5.c b/SCR3.1/TP3/ex5.c new file mode 100644 index 0000000..033f8d9 --- /dev/null +++ b/SCR3.1/TP3/ex5.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +#define SIZE 1000 +int search(const unsigned char * t,int start,int end) +{ + for (int i = start; i <= end; i++){ + int + +} + +int main(int argc , char * argv[]) +{ + int i; + unsigned char arr[SIZE]; + + srandom(time(NULL)); + + for (i = 0; i < SIZE; i++) + arr[i] = (unsigned char) (random() % 255) + 1; + + printf("Enter a number between 0 and %d: ", SIZE); + scanf(" %d", &i); + if (i >= 0 && i < SIZE) arr[i] = 0; + + if (search(arr,0,SIZE-1)) + printf("Found !\n"); + else + printf("Not found !\n"); + return EXIT_SUCCES; +} + + diff --git a/SCR3.1/TP3/fils.c b/SCR3.1/TP3/fils.c new file mode 100644 index 0000000..2855f6a --- /dev/null +++ b/SCR3.1/TP3/fils.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include + + +int main(void){ + pid_t p; + int status; + p = fork(); + switch ((int) p) { + case 0 : + printf("Retour de fork : %d, je suis le fils !\n", (int) p); + printf("Mon PID est : %d\n", (int) getpid()); + printf("Mon PPID est : %d\n", (int) getppid()); + sleep(4); + exit(2); + break; + + case -1: + printf("Ca s'est mal passé, aucun fils n'aura été engendré"); + exit(2); + break; + + default : + printf("Retour de fork : %d, je suis le père\n" , (int) p); + printf("Mon PID est : %d\n", (int) getpid()); + printf("Mon PPID est : %d\n", (int) getppid()); + wait(&status); + printf("Voici le code a renvoyé %d en code de sortie\n", WEXITSTATUS(status)); + execl("/usr/bin/ps", "ps", "-ef", NULL); + exit(2); + } + return EXIT_SUCCESS; +} + diff --git a/SCR3.1/TP3/tp3-reponses.txt b/SCR3.1/TP3/tp3-reponses.txt index 862a588..e30346e 100644 --- a/SCR3.1/TP3/tp3-reponses.txt +++ b/SCR3.1/TP3/tp3-reponses.txt @@ -9,4 +9,4 @@ Deuxième code : Le fork est avant l'ouverture donc chaque processus à son prop Exercice 3) Le code copie le contenu d'une fichier vers un autre -En décommentant le fork +En décommentant le fork, deux processus lisent et écrivent simultanément en espérant que dans l'idéal avec deux processus A et B, A lise et écrive puis qu'après B fasse de même ce qui n'est pas forcément le cas et crée des fichiers de sortie avec un contenu différent que celui d'entrée