Compare commits

..

4 Commits

Author SHA1 Message Date
b92c10d3d8 Ajout exo5 2025-08-17 13:25:54 +00:00
9744c9612c Ajout Thread 2025-08-16 07:34:54 +00:00
fd4d317d7f Ajouter reset.sh 2025-08-12 08:53:44 +00:00
b46722b3e6 Ajout exo3 2025-08-11 14:29:20 +00:00
13 changed files with 259 additions and 0 deletions

View File

@@ -9,6 +9,8 @@
*/ */
int sem_create(key_t cle, int initval); int sem_create(key_t cle, int initval);
/** /**
* take a token on the semaphore semid or wait if none available * take a token on the semaphore semid or wait if none available
*/ */

View File

@@ -20,7 +20,12 @@ void t2()
} }
int main () { int main () {
int semt1 = sem_create(CLE_SEM_T1,0);
int semt2 = sem_create(CLE_SEM_T2,0);
t1(); t1();
V(semt1);
t2(); t2();
V(semt2);
return 0; return 0;
} }

BIN
ANALE-1/EXO3/RESOLUTION/a.out Executable file

Binary file not shown.

BIN
ANALE-1/EXO3/RESOLUTION/pipeline Executable file

Binary file not shown.

View File

@@ -0,0 +1,83 @@
// pipeline.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
int main(void) {
int tube1[2],tube2[2];
int res1 = pipe(tube1);
if (res1 == -1){
perror("Création Pipe 1"); exit(-1);
}
int res2 = pipe(tube2);
if (res2 == -1){
perror("Création Pipe 1"); exit(-1);
}
// --- CUT ---
pid_t pid_cut = fork();
if (pid_cut == -1) { perror("fork cut"); exit(EXIT_FAILURE); }
if (pid_cut == 0) {
close(tube1[1]);
close(tube2[0]);
if (dup2(tube1[0], STDIN_FILENO) == -1) { perror("dup2 cut in"); _exit(1); }
if (dup2(tube2[1], STDOUT_FILENO) == -1) { perror("dup2 cut out"); _exit(1); }
close(tube1[0]);
close(tube2[1]);
execlp("cut", "cut", "-d,", "-f3", NULL);
perror("execlp cut");
_exit(127);
}
// SORT
pid_t pid_sort = fork();
if (pid_sort == -1) { perror("fork sort"); exit(EXIT_FAILURE); }
if (pid_sort == 0) {
close(tube1[0]); close(tube1[1]);
close(tube2[1]);
if (dup2(tube2[0], STDIN_FILENO) == -1) { perror("dup2 sort in"); _exit(1); }
close(tube2[0]);
int fd = open("sortie", O_CREAT | O_WRONLY | O_TRUNC, 0644);
if (fd == -1) { perror("open sortie"); _exit(1); }
if (dup2(fd, STDOUT_FILENO) == -1) { perror("dup2 sortie"); _exit(1); }
close(fd);
execlp("sort", "sort", NULL);
perror("execlp sort");
_exit(127);
}
// --- GREP ---
pid_t pid_grep = fork();
if (pid_grep == -1) { perror("fork grep"); exit(EXIT_FAILURE); }
if (pid_grep == 0) {
close(tube2[0]); close(tube2[1]);
close(tube1[0]);
int fd = open("server.log", O_RDONLY);
if (fd == -1) { perror("open server.log"); _exit(1); }
if (dup2(fd, STDIN_FILENO) == -1) { perror("dup2 grep in"); _exit(1); }
close(fd);
if (dup2(tube1[1], STDOUT_FILENO) == -1) { perror("dup2 grep out"); _exit(1); }
close(tube1[1]);
execlp("grep", "grep", "invalid credentials", NULL);
perror("execlp grep");
_exit(127);
}
// Parent
close(tube1[0]); close(tube1[1]);
close(tube2[0]); close(tube2[1]);
int status;
waitpid(pid_grep, &status, 0);
waitpid(pid_cut, &status, 0);
waitpid(pid_sort, &status, 0);
return 0;
}

BIN
ANALE-1/EXO3/SUJET/a.out Executable file

Binary file not shown.

View File

66
ANALE-1/EXO3/SUJET/sortie Normal file
View File

@@ -0,0 +1,66 @@
user_id: 1000
user_id: 1001
user_id: 1002
user_id: 1002
user_id: 1002
user_id: 1006
user_id: 1006
user_id: 1007
user_id: 1010
user_id: 1011
user_id: 1011
user_id: 1011
user_id: 1012
user_id: 1014
user_id: 1019
user_id: 1021
user_id: 1022
user_id: 1023
user_id: 1025
user_id: 1025
user_id: 1027
user_id: 1028
user_id: 1030
user_id: 1031
user_id: 1032
user_id: 1034
user_id: 1034
user_id: 1035
user_id: 1036
user_id: 1037
user_id: 1038
user_id: 1038
user_id: 1039
user_id: 1039
user_id: 1043
user_id: 1043
user_id: 1047
user_id: 1050
user_id: 1054
user_id: 1058
user_id: 1064
user_id: 1064
user_id: 1064
user_id: 1066
user_id: 1066
user_id: 1066
user_id: 1069
user_id: 1070
user_id: 1071
user_id: 1074
user_id: 1074
user_id: 1076
user_id: 1078
user_id: 1078
user_id: 1079
user_id: 1080
user_id: 1081
user_id: 1081
user_id: 1084
user_id: 1087
user_id: 1093
user_id: 1094
user_id: 1094
user_id: 1096
user_id: 1096
user_id: 1097

BIN
ANALE-1/EXO4/Thread Executable file

Binary file not shown.

45
ANALE-1/EXO4/thread.c Normal file
View File

@@ -0,0 +1,45 @@
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
struct structArg {
pthread_mutex_t* mutex;
};
void* func1(void* arg){
struct structArg* args = arg;
pthread_mutex_lock(args->mutex);
for(int i =1;i<1500;i++){
printf("OK - 1 - %d\n",i);
}
pthread_mutex_unlock(args->mutex);
pthread_exit(NULL);
}
void* func2(void* arg){
struct structArg* args = arg;
pthread_mutex_lock(args->mutex);
for(int i =1;i<1000;i++){
printf("OK - 2 - %d\n",i);
}
pthread_mutex_unlock(args->mutex);
pthread_exit(NULL);
}
int main(void){
pthread_t p1,p2;
pthread_mutex_t mutex;
pthread_mutex_init(&mutex,NULL);
struct structArg args;
args.mutex = &mutex;
pthread_create(&p1,NULL,func1,&args);
pthread_create(&p2,NULL,func2,&args);
pthread_join(p1,NULL);
pthread_join(p2,NULL);
pthread_mutex_destroy(&mutex);
return 0;
}

BIN
ANALE-1/EXO5/launcher Executable file

Binary file not shown.

54
ANALE-1/EXO5/launcher.c Normal file
View File

@@ -0,0 +1,54 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
int main(void)
{
int tube[2];
int tube2[2];
int res = pipe(tube);
if (res == -1) {
perror("Création Pipe"); exit(-1);
}
int res2 = pipe(tube2);
if (res2 == -1) {
perror("Création Pipe"); exit(-1);
}
pid_t pid_wc = fork();
if (pid_wc == 0) {
// lit depuis tube -> stdin
close(tube[1]);
dup2(tube[0], 0);
close(tube[0]);
// écrit vers tube2 -> stdout
close(tube2[0]); // on ne lit pas tube2 ici
dup2(tube2[1], 1);
close(tube2[1]);
execlp("cat", "cat",NULL); // ou "wc", "-c", NULL pour compter octets, etc.
perror("cat wc");
_exit(1);
}
pid_t pid_data = fork();
if (pid_data == 0) {
close(tube[0]);
write(tube[1],"Bonjour tous le monde\nJe m'appelle Ronan\n",strlen("Bonjour tous le monde\nJe m'appelle Ronan\n"));
close(tube[1]);
}
pid_t pid_read = fork();
if (pid_read == 0) {
char temp[500];
close(tube2[1]);
read(tube2[0],&temp,sizeof(temp));
printf("%s",temp);
close(tube2[0]);
}
return 0;
}

4
reset.sh Normal file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
git fetch origin
git reset --hard origin/main # remplace main par ta branche réelle
git clean -fd