ajout fichiers
This commit is contained in:
25
TP2/Exemples/Exemple1.c
Normal file
25
TP2/Exemples/Exemple1.c
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
pid_t pid; // pour récupérer le pid du nouveau processus
|
||||
|
||||
int main() {
|
||||
|
||||
switch(pid = fork()) {
|
||||
case (pid_t) -1: // l’appel de fork a échoué
|
||||
perror("Création de processus");
|
||||
exit(2);
|
||||
case (pid_t)0: // ici, ça concerne le processus fils
|
||||
printf("valeur de fork dans le fils = %d\n",pid);
|
||||
printf("je suis le processus %d de père %d\n",getpid(), getppid());
|
||||
printf("fin du processus fils\n");
|
||||
exit(0);
|
||||
default: // ici, c’est le processus père
|
||||
printf("valeur de fork dans le père = %d\n",pid);
|
||||
printf("je suis le processus %d de père %d\n",getpid(), getppid());
|
||||
printf("fin du processus père\n");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
20
TP2/Exemples/Exemple2.c
Normal file
20
TP2/Exemples/Exemple2.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
int n = 5;
|
||||
pid_t fils_pid;
|
||||
|
||||
for (int i=0; i < n; i++) {
|
||||
fils_pid = fork();
|
||||
|
||||
if (fils_pid > 0) break;
|
||||
|
||||
printf("Processus %d avec père %d n=%d\n", getpid(), getppid(),i);
|
||||
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
26
TP2/Exemples/Exemple3.c
Normal file
26
TP2/Exemples/Exemple3.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
int n = 5;
|
||||
pid_t fils_pid;
|
||||
|
||||
for (int i=0; i < n; i++) {
|
||||
fils_pid = fork();
|
||||
|
||||
if (fils_pid > 0) break;
|
||||
|
||||
printf("Processus %d avec père %d\n", getpid(), getppid());
|
||||
}
|
||||
|
||||
for (int j = 0; j < 10000; j++) {
|
||||
for (int k=0; k < 1000; k++) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
BIN
TP2/Exemples/a.out
Executable file
BIN
TP2/Exemples/a.out
Executable file
Binary file not shown.
Reference in New Issue
Block a user