while(index<Y) // Y is the number of childs to be created
{
if(p_id>0){/
p_id=fork();
if(p_id>0){//Parent
pid_list[index]=p_id;
index++;
}elseif (p_id==0) {//Si es el nuevo hijo
anotherclass::do_some_stuff_and_stay_there();
exit(EXIT_SUCCESS);
}
elseif(p_id<0){
printf("Error creating child"); }
}
}
Every child should call do_some_stuff_and_stay_there() , that function at some point will end, but they are executed independently.
Later I have to check every while whether those processes have ended, which should happen when the function ended.
1 2 3 4 5 6 7 8 9
processfolder="/proc/"+pid_number;
if (access(processfolder.c_str(), F_OK) != -1){
printf(" Process is running\n");
act=true;
}
else{
act=false;
printf(" Process is NOT running\n");
}
But it always detects "process is running" because the process gets stuck in a <defunct> status, and I can't kill the parent so I run out of ideas how to detect that and kill it. ¿Any clue ?