1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main () {
pid_t pidf; //Initialisé avec la fonction fork()
pid_t pid = getpid(); //Obtenir PID du processus en cours
pid_t ppid = getppid(); //Obtenir le processus parent
pidf = fork(); //Création du processus enfant
if (pidf == 0) { //On est dans le processus enfant
printf("Fils - Mon PID est %d\n", pid);
printf("Fils - mon PID parent est %d.\n", ppid);
}
else { //On est dans le processus parent
printf("Parent - Mon pid est %d\n", pid);
printf("Parent - pidf est %d.\n", pidfils);
}
return 0 ;
} |