LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 09-23-2009, 06:05 PM   #1
ajb181
LQ Newbie
 
Registered: Sep 2009
Posts: 8

Rep: Reputation: 0
Kill process handling


Hi all. Im new to linux and having problems killing a task in my app.

im sending

if (kill(_main_thread, SIGINT) ==-1)
{
os::sleep(100);
kill(_main_thread, SIGINT);
}

t = waitpid (_main_thread, NULL, WNOHANG);

and i keep getting the error message

ECHILD 10 /* No child processes */

from waitpid function call. I have check and it is calling the correct pid number of the task.

When i check the function list i see the task listed as a zombie process under the correct pid number.

THe app i am killing is mpg321. i check the source and this is what is done on the SIGINT

RETSIGTYPE handle_signals(int sig)
{
static struct timeval last_signal = { 0, 0 };
struct timeval curr_tv;

gettimeofday(&curr_tv, NULL);

if (sig == SIGINT)
{
DBG_INFO(("SIGINT Got\n"));
// if (((curr_tv.tv_sec - last_signal.tv_sec) * 1000000 + (curr_tv.tv_usec - last_signal.tv_usec)) < 1000000) /* Allow a short delay to kill mpg321 */
{
DBG_INFO(("SIGINT Quit\n"));
quit_now = 1;
}

last_signal.tv_sec = curr_tv.tv_sec;
last_signal.tv_usec = curr_tv.tv_usec;

stop_playing_file = 1;

}
else if (sig == -1) /* initialize */
{
last_signal.tv_sec = curr_tv.tv_sec;
last_signal.tv_usec = curr_tv.tv_usec;
}
}

and this is done on the exit of main

if(playdevice)
ao_close(playdevice);

ao_shutdown();
/*Restoring TTY*/
set_tty_restore();
if (ctty)
fclose(ctty);

return(0);

What signal is ment to be sent so the wait function will remove the program from the task list?

Thanks you your time
Alex
 
Old 09-23-2009, 06:37 PM   #2
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by ajb181 View Post

[ snip ]

What signal is ment to be sent so the wait function will remove the program from the task list?

Thanks you your time
Alex
In most cases, the reliable way to kill a process is:

Code:
# kill -9 PID
I am sure you will know how to create this same result in code.
 
Old 09-23-2009, 08:46 PM   #3
ajb181
LQ Newbie
 
Registered: Sep 2009
Posts: 8

Original Poster
Rep: Reputation: 0
If you could elaborate that would be fantastic.

Thanks Alex
 
Old 09-23-2009, 09:52 PM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by ajb181 View Post
If you could elaborate that would be fantastic.

Thanks Alex
If when replying you could quote the part you're having a problem with, that would be fantastic.

Rewrite your routine this way:

Code:
if (kill(_main_thread, SIGKILL) ==-1)
{
   os::sleep(100);
   kill(_main_thread, SIGKILL);
}
 
Old 09-24-2009, 10:18 PM   #5
ajb181
LQ Newbie
 
Registered: Sep 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Have tried using SIGKILL with no success the task still zombies.

MPG321 only has handling for SIGINT .. See below

Code:
RETSIGTYPE handle_signals(int sig)
{
static struct timeval last_signal = { 0, 0 };
struct timeval curr_tv;

gettimeofday(&curr_tv, NULL);

if (sig == SIGINT)
{
DBG_INFO(("SIGINT Got\n"));
// if (((curr_tv.tv_sec - last_signal.tv_sec) * 1000000 + (curr_tv.tv_usec - last_signal.tv_usec)) < 1000000) /* Allow a short delay to kill mpg321 */
{
DBG_INFO(("SIGINT Quit\n"));
quit_now = 1;
}

last_signal.tv_sec = curr_tv.tv_sec;
last_signal.tv_usec = curr_tv.tv_usec;

stop_playing_file = 1;

}
else if (sig == -1) /* initialize */
{
last_signal.tv_sec = curr_tv.tv_sec;
last_signal.tv_usec = curr_tv.tv_usec;
}
}
 
Old 11-08-2009, 10:22 PM   #6
ajb181
LQ Newbie
 
Registered: Sep 2009
Posts: 8

Original Poster
Rep: Reputation: 0
I still do not have a solution for this problem. Could anyone Please help?

The thread calling waitpid is from the parent forked task.

Last edited by ajb181; 11-08-2009 at 10:46 PM.
 
  


Reply

Tags
kill, task


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash `kill`: process 'B' silently dies; but process 'A' = `kill` spews back debris! GrapefruiTgirl Programming 9 06-23-2009 10:42 AM
How to get the PID of the process giving kill signal to a process? hariprd Programming 2 11-27-2008 04:10 AM
Shell Script : Kill a running process when another process starts ashmew2 Linux - General 3 08-20-2008 04:47 AM
cannot kill process (kill -9 does not work) mazer13a Linux - General 1 05-27-2005 03:32 PM
Zombie Process Handling kghoshal Linux - Newbie 2 07-21-2003 10:10 AM


All times are GMT -5. The time now is 04:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration