Controle machine ASR
This commit is contained in:
BIN
CtrlProc-2021/Exo3/exo3
Executable file
BIN
CtrlProc-2021/Exo3/exo3
Executable file
Binary file not shown.
63
CtrlProc-2021/Exo3/exo3.c
Normal file
63
CtrlProc-2021/Exo3/exo3.c
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/* Ce programme n'est pas complet : j'arrive à récupérer les chiffres et lettres
|
||||
sur la sortie standard (sauf la première étrangement) mais je n'ai pas le temps pour le terminer */
|
||||
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
pid_t pid1, pid2;
|
||||
char a;
|
||||
int tube[2], l=0, c=0;
|
||||
|
||||
pid1 = fork();
|
||||
pid2 = fork();
|
||||
|
||||
if(pipe (tube) != 0){
|
||||
perror("error pipe");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if(pid1 == 0){
|
||||
printf("Processus père de pid : %d, avec fils1 de pid : %d\n", getpid(), getppid());
|
||||
close(tube[1]);
|
||||
while(read (tube[0], &a, 1) > 0){
|
||||
if(isdigit (a)){
|
||||
c++;
|
||||
} else if (isalnum(a)) {
|
||||
l = l;
|
||||
}
|
||||
printf("%d chiffres\n", c);
|
||||
}
|
||||
}
|
||||
else if (pid2 == 0){
|
||||
printf("Processus père de pid : %d, avec fils2 de pid : %d\n", getpid(), getppid());
|
||||
close(tube[1]);
|
||||
while(read (tube[0], &a, 1) > 0){
|
||||
if(isalnum(a)){
|
||||
l++;
|
||||
} else if (isdigit (a)){
|
||||
c = c;
|
||||
}
|
||||
printf("%d lettres\n", l);
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
close (tube[0]);
|
||||
while (read (0, &a, 1) >0)
|
||||
if (isalnum(a))
|
||||
write (tube[1], &a, 1);
|
||||
|
||||
close(tube[1]);
|
||||
wait(NULL);
|
||||
}
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Reference in New Issue
Block a user