Re: [LIP] [Update] Sending TERM, and signal handler issue.

Amit Kucheria <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Message-ID <[email protected]>
On Wed, 20 Oct 2004, Amarendra Godbole wrote:

> Hi,
>
> void term_handle(int signo) {
>        printf("Okay, caught %d.\n", signo);
>        printf("Going to sleep.\n", signo);
>        sleep(15);
> }
> ----<cut here>----

> 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.

You might want to disable the TERM signal when you enter the 
term_handler().

Try adding the following to term_handler():

sigset_t sig;

sigemptyset(&sig);
sigaddset(&sig, SIGTERM);
sigprocmask(SIG_BLOCK, &sig, NULL);

Regards,
Amit

-- 
I'm an angel!!! Honest!
The horns are just there to hold the halo up straight.
-----------------------------------------------------
Amit Kucheria             | amitk@ NOSPAM ittc.ku.edu
Wireless Systems Engineer | 760-822-8529
Metric Systems Corp.      | Vista, CA 92083
-----------------------------------------------------


-------------------------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.