Ajout exo5
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
*/
|
||||
int sem_create(key_t cle, int initval);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* take a token on the semaphore semid or wait if none available
|
||||
*/
|
||||
|
||||
@@ -20,7 +20,12 @@ void t2()
|
||||
}
|
||||
|
||||
int main () {
|
||||
int semt1 = sem_create(CLE_SEM_T1,0);
|
||||
int semt2 = sem_create(CLE_SEM_T2,0);
|
||||
|
||||
t1();
|
||||
V(semt1);
|
||||
t2();
|
||||
V(semt2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
ANALE-1/EXO5/launcher
Executable file
BIN
ANALE-1/EXO5/launcher
Executable file
Binary file not shown.
54
ANALE-1/EXO5/launcher.c
Normal file
54
ANALE-1/EXO5/launcher.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user