ajout fichiers TP
This commit is contained in:
parent
8f44fb0636
commit
1cb87a23e7
BIN
Controle/Exercice 1/A
Executable file
BIN
Controle/Exercice 1/A
Executable file
Binary file not shown.
17
Controle/Exercice 1/A.c
Normal file
17
Controle/Exercice 1/A.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
}
|
BIN
Controle/Exercice 1/A.o
Normal file
BIN
Controle/Exercice 1/A.o
Normal file
Binary file not shown.
BIN
Controle/Exercice 1/B1
Executable file
BIN
Controle/Exercice 1/B1
Executable file
Binary file not shown.
17
Controle/Exercice 1/B1.c
Normal file
17
Controle/Exercice 1/B1.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
}
|
BIN
Controle/Exercice 1/B1.o
Normal file
BIN
Controle/Exercice 1/B1.o
Normal file
Binary file not shown.
BIN
Controle/Exercice 1/C1
Executable file
BIN
Controle/Exercice 1/C1
Executable file
Binary file not shown.
8
Controle/Exercice 1/C1.c
Normal file
8
Controle/Exercice 1/C1.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
sleep(5);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
BIN
Controle/Exercice 1/C1.o
Normal file
BIN
Controle/Exercice 1/C1.o
Normal file
Binary file not shown.
BIN
Controle/Exercice 1/C2
Executable file
BIN
Controle/Exercice 1/C2
Executable file
Binary file not shown.
8
Controle/Exercice 1/C2.c
Normal file
8
Controle/Exercice 1/C2.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
sleep(5);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
BIN
Controle/Exercice 1/C2.o
Normal file
BIN
Controle/Exercice 1/C2.o
Normal file
Binary file not shown.
18
Controle/Exercice 1/Makefile
Normal file
18
Controle/Exercice 1/Makefile
Normal file
@ -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
|
1
Controle/Exercice 1/ok.txt
Normal file
1
Controle/Exercice 1/ok.txt
Normal file
@ -0,0 +1 @@
|
||||
watch -n 1 ps -o cmd -C A,B1,C1,C2 --forest dans un autre terminal
|
29
ExerciceSignaux.c
Normal file
29
ExerciceSignaux.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include <sys/wait.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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);
|
||||
|
||||
}
|
21
TP3/Ex1.c
Normal file
21
TP3/Ex1.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
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;
|
||||
}
|
30
TP3/Ex2.c
Normal file
30
TP3/Ex2.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
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;
|
||||
}
|
30
TP3/Ex3.c
Normal file
30
TP3/Ex3.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
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;
|
||||
}
|
13
TP3/Ex4.c
Normal file
13
TP3/Ex4.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
1
TP3/fichier
Normal file
1
TP3/fichier
Normal file
@ -0,0 +1 @@
|
||||
abcdefghijk127440)^liojh3uijb4567 k;ljilkj
|
Loading…
Reference in New Issue
Block a user