Controle machine ASR
This commit is contained in:
BIN
CtrlProc-2021/Exo2/a.out
Executable file
BIN
CtrlProc-2021/Exo2/a.out
Executable file
Binary file not shown.
BIN
CtrlProc-2021/Exo2/pere
Executable file
BIN
CtrlProc-2021/Exo2/pere
Executable file
Binary file not shown.
77
CtrlProc-2021/Exo2/pere.c
Normal file
77
CtrlProc-2021/Exo2/pere.c
Normal file
@@ -0,0 +1,77 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Je laisse volontairement cette fonction statique, qui empêche mon programme de fonctionner car je n'ai pas complété l'exercice, elle
|
||||
aurait normalement servie à afficher le premier processus à avoir terminer grâce aux signaux
|
||||
|
||||
static void first_proc(int sig);
|
||||
|
||||
static void first_proc(int sig){
|
||||
switch (sig){
|
||||
case SIGUSR1:
|
||||
printf("Le premier fils a terminé en premier");
|
||||
break;
|
||||
|
||||
case SIGUSR2:
|
||||
printf("Le second fils a terminé en premier");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
pid_t pid1, pid2;
|
||||
|
||||
pid1 = fork();
|
||||
|
||||
pid2 = fork();
|
||||
|
||||
/* De même que plus haut dans mon programme, il s'agit ici de la gestion d'erreur dans le cas ou ma fonction fonctionnait
|
||||
|
||||
if(signal(SIGUSR1,first_proc) == SIG_ERR) {
|
||||
perror("Error sig");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if(signal(SIGUSR2,first_proc) == SIG_ERR) {
|
||||
perror("Error sig");
|
||||
exit(-1);
|
||||
} */
|
||||
|
||||
if(pid1==0) {
|
||||
printf("Processus père de pid : %d, avec fils1 de pid : %d\n", getpid(), getppid());
|
||||
if(execlp("ls", "ls", "-l", NULL) == -1) {
|
||||
perror("exec");
|
||||
exit(-1);
|
||||
}
|
||||
} else {
|
||||
wait(NULL);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
if(pid2==0){
|
||||
printf("Processus père de pid : %d, avec fils2 de pid : %d\n", getpid(), getppid());
|
||||
if(execlp("ps", "ps", "-l", NULL) == -1) {
|
||||
perror("exec");
|
||||
exit(-1);
|
||||
}
|
||||
} else {
|
||||
wait(NULL);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user