diff --git a/Controle/Exercice 1/A b/Controle/Exercice 1/A new file mode 100755 index 0000000..aa43db1 Binary files /dev/null and b/Controle/Exercice 1/A differ diff --git a/Controle/Exercice 1/A.c b/Controle/Exercice 1/A.c new file mode 100644 index 0000000..e1cc8a5 --- /dev/null +++ b/Controle/Exercice 1/A.c @@ -0,0 +1,17 @@ +#include +#include +#include + +int main(int argc, char const *argv[]) { + char* arg[3] = {"B1", "1", NULL}; + if (!fork()) { + execvp("B1", arg); + } else { + if (!fork()) { + arg[1] = "2"; + execvp("B1", arg); + } + } + sleep(5); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/Controle/Exercice 1/A.o b/Controle/Exercice 1/A.o new file mode 100644 index 0000000..4553001 Binary files /dev/null and b/Controle/Exercice 1/A.o differ diff --git a/Controle/Exercice 1/B1 b/Controle/Exercice 1/B1 new file mode 100755 index 0000000..6621b44 Binary files /dev/null and b/Controle/Exercice 1/B1 differ diff --git a/Controle/Exercice 1/B1.c b/Controle/Exercice 1/B1.c new file mode 100644 index 0000000..60cb393 --- /dev/null +++ b/Controle/Exercice 1/B1.c @@ -0,0 +1,17 @@ +#include +#include +#include + +int main(int argc, char const *argv[]) { + char* arg[2] = {NULL, NULL}; + if (!fork()) { + if (argv[1][0] == '1') { + arg[0] = "C1"; + } else { + arg[0] = "C2"; + } + execvp(arg[0], arg); + } + sleep(5); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/Controle/Exercice 1/B1.o b/Controle/Exercice 1/B1.o new file mode 100644 index 0000000..5ba5123 Binary files /dev/null and b/Controle/Exercice 1/B1.o differ diff --git a/Controle/Exercice 1/C1 b/Controle/Exercice 1/C1 new file mode 100755 index 0000000..1210dd1 Binary files /dev/null and b/Controle/Exercice 1/C1 differ diff --git a/Controle/Exercice 1/C1.c b/Controle/Exercice 1/C1.c new file mode 100644 index 0000000..4fa6daa --- /dev/null +++ b/Controle/Exercice 1/C1.c @@ -0,0 +1,8 @@ +#include +#include +#include + +int main(int argc, char const *argv[]) { + sleep(5); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/Controle/Exercice 1/C1.o b/Controle/Exercice 1/C1.o new file mode 100644 index 0000000..a0034d0 Binary files /dev/null and b/Controle/Exercice 1/C1.o differ diff --git a/Controle/Exercice 1/C2 b/Controle/Exercice 1/C2 new file mode 100755 index 0000000..fd2632d Binary files /dev/null and b/Controle/Exercice 1/C2 differ diff --git a/Controle/Exercice 1/C2.c b/Controle/Exercice 1/C2.c new file mode 100644 index 0000000..4fa6daa --- /dev/null +++ b/Controle/Exercice 1/C2.c @@ -0,0 +1,8 @@ +#include +#include +#include + +int main(int argc, char const *argv[]) { + sleep(5); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/Controle/Exercice 1/C2.o b/Controle/Exercice 1/C2.o new file mode 100644 index 0000000..fcb1a38 Binary files /dev/null and b/Controle/Exercice 1/C2.o differ diff --git a/Controle/Exercice 1/Makefile b/Controle/Exercice 1/Makefile new file mode 100644 index 0000000..c3601b0 --- /dev/null +++ b/Controle/Exercice 1/Makefile @@ -0,0 +1,18 @@ +CC=gcc + + +A: A.o B1 + $(CC) -o A A.o + +B1: B1.o C1 C2 + $(CC) -o B1 B1.o + +C1: C1.o + $(CC) -o C1 C1.o + +C2: C2.o + $(CC) -o C2 C2.o + + +run: + A \ No newline at end of file diff --git a/Controle/Exercice 1/ok.txt b/Controle/Exercice 1/ok.txt new file mode 100644 index 0000000..f3a9a4b --- /dev/null +++ b/Controle/Exercice 1/ok.txt @@ -0,0 +1 @@ +watch -n 1 ps -o cmd -C A,B1,C1,C2 --forest dans un autre terminal \ No newline at end of file diff --git a/ExerciceSignaux.c b/ExerciceSignaux.c new file mode 100644 index 0000000..252b00f --- /dev/null +++ b/ExerciceSignaux.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + pid_t pid; + int status; + + pid = fork(); + + + if (pid != 0) { + printf("le pid du fils est %d\n", pid); + waitpid(pid, &status, WUNTRACED); + + if (WIFSIGNALED(status)) { + printf("tué par le signal %d\n", WTERMSIG(status)); + } else if (WIFSTOPPED(status)) { + printf("arrêté par le signal %d\n", WSTOPSIG(status)); + } + } else { + while(1){} + } + +exit(EXIT_SUCCESS); + +} \ No newline at end of file diff --git a/TP3/Ex1.c b/TP3/Ex1.c new file mode 100644 index 0000000..7885bf0 --- /dev/null +++ b/TP3/Ex1.c @@ -0,0 +1,21 @@ +#include +#include +#include +#include +#include + +int main(int argc, char const *argv[]) { + pid_t pid; + pid = fork(); + char *lel[3] = {"ls", "-l", NULL}; + if (pid==0) { + printf("pid de mon papa : %d\n", getppid()); + execvp("ls", lel); + + } else { + printf("pid de mon fiston : %d\n", pid); + wait(NULL); + + } + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/TP3/Ex2.c b/TP3/Ex2.c new file mode 100644 index 0000000..fc43912 --- /dev/null +++ b/TP3/Ex2.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + pid_t pid; + int i; + if (argc < 2) { + perror("Pas assez d'arguments"); + return EXIT_FAILURE; + } + if (argc > 9) { + perror("Trop d'arguments"); + return EXIT_FAILURE; + } + pid = fork(); + + if (pid==0) { + printf("pid de mon papa : %d\n", getppid()); + execvp(argv[1], argv+1); + + } else { + printf("pid de mon fiston : %d\n", pid); + wait(NULL); + + } + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/TP3/Ex3.c b/TP3/Ex3.c new file mode 100644 index 0000000..21fdf95 --- /dev/null +++ b/TP3/Ex3.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include +#include +#include +int main(int argc, char *argv[]) { + int pid, fp, i, j; + char ch[4]; + + fp = open("fichier", O_RDWR); + pid = fork(); + + if (pid == 0) { + for (i = 0; i < 4; i++) { + read(fp, ch, 4); + printf("hello fils : %s\n", ch); + sleep(4); + } + } else { + for (j = 0; j < 3; j++) { + read(fp, ch, 4); + printf("Hello père : %s\n", ch); + sleep(5); + } + wait(NULL); + close(fp); + } + return 1; +} \ No newline at end of file diff --git a/TP3/Ex4.c b/TP3/Ex4.c new file mode 100644 index 0000000..8bf9de9 --- /dev/null +++ b/TP3/Ex4.c @@ -0,0 +1,13 @@ +#include +#include + +int main(int argc, char const *argv[]) { + int i = 0; + char* envstr = getenv("RUN_0"); + while(envstr != NULL) { + printf("%s", envstr); + i++; + envstr = getenv("RUN_"+ (i+30)); + } + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/TP3/a.out b/TP3/a.out new file mode 100755 index 0000000..745714a Binary files /dev/null and b/TP3/a.out differ diff --git a/TP3/fichier b/TP3/fichier new file mode 100644 index 0000000..8198426 --- /dev/null +++ b/TP3/fichier @@ -0,0 +1 @@ +abcdefghijk127440)^liojh3uijb4567 k;ljilkj \ No newline at end of file diff --git a/TP3/fils1 b/TP3/fils1 new file mode 100755 index 0000000..90cc459 Binary files /dev/null and b/TP3/fils1 differ diff --git a/a.out b/a.out new file mode 100755 index 0000000..33ba0f2 Binary files /dev/null and b/a.out differ