La valeur pid parent a été confondue avec le bloc de processus enfant. Mon programme est donné ci-dessous:ID de processus enfant et parent
int main(int argc, char *argv[])
{
pid_t pid;
pid=fork();
if(pid==-1){
perror("fork failure");
exit(EXIT_FAILURE);
}
else if(pid==0){
printf("pid in child=%d and parent=%d\n",getpid(),getppid());
}
else{
printf("pid in parent=%d and childid=%d\n",getpid(),pid);
}
exit(EXIT_SUCCESS);
}
Sortie: pid dans parent = 2642 et childID = 2643
pid chez l'enfant = 2643 et parent = 1
"Programmation Unix avancée", il dit ce processus enfant peut obtenir l'ID du processus parent en utilisant la fonction getppid(). Mais ici, je reçois "1" qui est "init" processus id.
Comment puis-je obtenir la valeur pid parent dans le bloc de processus enfant. Aidez-moi à obtenir une sortie.
J'ai exécuté dans "Linux Mint OS" mais dans "OS WindRiver" je ne reçois pas ce problème. Ce programme change-t-il le comportement en fonction du système d'exploitation?
double possible de [Pourquoi getppid() du retour de l'enfant 1] (http://stackoverflow.com/questions/16078188/why-getppid-from-the-child-return-1) – melpomene