[LIP] [Update] Sending TERM, and signal handler issue.
Amarendra Godbole <[email protected]>
| Newsgroups | gmane.user-groups.linux.india.programmers |
|---|---|
| Organization | GE Security - IBC |
| Message-ID | <[email protected]> |
Hi,
I had posted this query yesterday about a suspected signal handler
screwup. I need your inputs to go about this issue, here is a program
that simulates this behavior -
----<cut here>----
#include <stdio.h>
#include <signal.h>
void term_handle(int signo);
int main(void)
{
signal(SIGTERM, term_handle);
/* we just sleep - simulating some processing */
sleep(5);
return 0;
}
void term_handle(int signo) {
printf("Okay, caught %d.\n", signo);
printf("Going to sleep.\n", signo);
sleep(15);
}
----<cut here>----
Here is a sample run, where I keep on sending SIGTERM to this program,
and it is hung (or appears to hang.) This way it may never come out of
the loop - if SIGTERM is being sent to it repeatedly.
[root@ibcjupiter2 root]# date
Tue Oct 19 00:10:21 EDT 2004
[root@ibcjupiter2 root]# ./sig_test &
[1] 21487
[root@ibcjupiter2 root]# kill -TERM 21487
[root@ibcjupiter2 root]# Okay, caught 15.
Going to sleep.
[root@ibcjupiter2 root]# kill -TERM 21487
[root@ibcjupiter2 root]# Okay, caught 15.
Going to sleep.
[root@ibcjupiter2 root]# kill -TERM 21487
[root@ibcjupiter2 root]# Okay, caught 15.
Going to sleep.
[root@ibcjupiter2 root]# kill -TERM 21487
[root@ibcjupiter2 root]# Okay, caught 15.
Going to sleep.
[root@ibcjupiter2 root]# date
Tue Oct 19 00:11:14 EDT 2004
[root@ibcjupiter2 root]#
[1]+ Done ./sig_test
This is _exactly_ what happens in my case too. From a shell script, a
kill -TERM is being sent to it, which returns with a status of 0. Then
in a loop, its pid is being grepped for - and if present, another kill
is posted to it. My signal handler requires some 8 seconds, before it
returns.
Is there a better way of doing this, so that it does not go into this
infinite loop ? Yes, altering the shell script is one possibility -
but I wanted to know if there is a better way to do this using
signal() (or sigaction())Thanks in advance.
Cheers,
Amar
--
Destiny is not a matter of chance, it is a matter of choice.
Subject:
Sending TERM, and signal handler issue.
From:
Amarendra Godbole <[email protected]>
Date:
Mon, 18 Oct 2004 15:58:27 +0530
To:
linux-india-programmers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Hi,
I have a process `foo,' which runs along with its 10 children. Now,
foo.c has an handler for SIGTERM, which first reaps its children, and
then goes off.
foo is started and stopped from a startup script, in runlevel 3. This
script has the typical `kill -TERM <foo_pid>,' to kill foo. foo
handles this TERM and does a proper cleanup. This script when executed
on command line executes fine...
...but when my system is shutting down - I run into real trouble. It
seems that the `kill' never actually kills foo, and the shutdown
script goes in a loop trying to kill it (I have the loop put there.)
Also, while executing it from the command line, I see that the kill is
being done three to four times, before foo actually goes down.
I suspect some issue with the way foo handles SIGTERM. Can someone
confirm this ? foo is a part of legacy code.
Thanks in advance.
Cheers,
Amar
--
Destiny is not a matter of chance, it is a matter of choice.
-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl