I am trying to Kill a child task and i can not do it without it becomming a zombie.
This is on an embedded platform and the Child process is running MPG321 with the execvp() command.
I tryed everything i could find on the net with no luck. If you could help with this problem and my understanding of why this is occuring that would be most appreciated. Have been stuck with this problem for some months now..
when killing task i get the error number 10 which i think is #define ECHILD 10 /* No child processes */ But i have checked that i am sending kill the correct PID number.??
this is the calling task
Code:
/* Create the pipe. */
if (pipe(inst->_info_pipe))
{
//__SERVERDBG("MP3: Pipe failed");
__EXCEPT(EXCEPTION_APPLICATION);
}
/* Create the child process. */
frk_pid = fork ();
if (frk_pid == (pid_t) 0)
{
/* This is the child process. */
dup2(inst->_info_pipe[1],2);
close(inst->_info_pipe[0]);
inst->_SongLen = 0;
/* set the group (session) id to this process for future killing */
setsid();
execvp(exec_bin,cmd_ptr);
exit(0);
}
//parent reading from pipe
inst->_main_thread = frk_pid;
close(inst->_info_pipe[1]);
inst->_info_pipe[1] = -1;
inst->_current_state = PLAYING;
int retrys = 0;
while(inst->_current_state == PLAYING) // wont return from here till song is finished
{
char Tmp[50];
int r = read(inst->_info_pipe[0], Tmp,50);
if(r > 0)
{
retrys = 0;
inst->ParseOutput(Tmp, r);
}
else
{
retrys++;
if(retrys == 2)
{
__SERVERDBG("retrys");
//inst->StopPlayerApp();
//inst->_current_state = STOPPED;
break;
}
if(inst->_current_state != PLAYING)
{
__SERVERDBG("No longer playing");
}
}
}
inst->FlushParser();
//Kill function
void MP3Controller::StopPlayerApp()
{
pid_t t = 0;
if(_main_thread == -1) // not thread running
return;
//Stop player
/*if (killpg(_main_thread, SIGINT) == -1)
{
// os::sleep(100);
//kill(-_main_thread, 2);
}*/
int killReturn = killpg(_main_thread, SIGINT) ;
if( killReturn == ESRCH) // pid does not exist
{
__SERVERDBG("Group does not exist!");
}
else if( killReturn == EPERM) // No permission to send signal
{
__SERVERDBG("No permission to send signal!");
}
else
__SERVERDBG("No problem sending sig!");
int childExitStatus;
t = waitpid (_main_thread, &childExitStatus, WNOHANG);
if (t != _main_thread)
{
__SERVERDBG("error %i" , errno);
// waitpid (_main_thread, NULL, 0);
}
_main_thread = -1;
// Close pipes
close(_info_pipe[0]); // shut pipe from MP3 app
_info_pipe[0] = -1;
FlushParser();
}