Catching "kill -9" and "^C"

Catching "kill -9" and "^C"

Post by Sam Y » Thu, 11 Jan 1996 04:00:00




>Can anyone show me how to catch kill -9 and ^C? I need do some shared memory cleanup before
>my program actually exits.

-9 (SIGKILL) can't be caught.  Otherwise,

my_cleanup()
{
   ...
   exit(1);

Quote:}

...
signal(SIGINT,my_cleanup);
signal(SIGHUP,my_cleanup);

OR (even better)

atexit(my_cleanup);

hope it helps.

-sam

 
 
 

Catching "kill -9" and "^C"

Post by Mark Seabor » Thu, 11 Jan 1996 04:00:00


Can anyone show me how to catch kill -9 and ^C? I need do some shared memory cleanup before
my program actually exits.
--
*********************************************************************



* Schaumburg, IL. 60196 | Voice     : 708/538-5303                  *
* Maildrop: IL02/Rm0442 | Fax       : 708/576-2619                  *
*********************************************************************
* AKA : Conan the Saute' Man                                        *
*                          .   .   .                                *
*                           .   .   .                               *
*                           .   .   .                               *
*                         .    .   .                                *
*          _____________________________                            *
*                      \              /                             *
*                       \____________/

 
 
 

Catching "kill -9" and "^C"

Post by Manfred Pe » Sat, 13 Jan 1996 04:00:00


: Can anyone show me how to catch kill -9 and ^C? I need do some shared memory cleanup before
: my program actually exits.

Signal 9 can't be catched. ^C is Signal 2 (SIGINT).

You should at least also hook SIGHUP and SIGTERM. To see why you should
hook SIGHUP, check man termio(7).

Don't use signal 9 to kill processes unless the process doesn't terminate
on a SIGTERM.

  #include <signal.h>

  void sighand (sig)
  int sig;
  {
    /*
        clean up and do an _exit(2) or do `signal (sig, sighand)' if you
        want to continue. Check signal(2) for more info.
    */
  }

  /* hook signal vectors. */
  signal (SIGINT, sighand);
  signal (SIGHUP, sighand);
  signal (SIGTERM, sighand);

pm

 
 
 

Catching "kill -9" and "^C"

Post by Rob De Langh » Sat, 13 Jan 1996 04:00:00



>Can anyone show me how to catch kill -9 and ^C? I need do some shared memory cleanup before
>my program actually exits.
>--
>*********************************************************************


Hy Mark,

signal 9, you simply cannot catch (see the man pages)

signal 2, you can catch with the signal() system call (see man pages).

Rob

 
 
 

Catching "kill -9" and "^C"

Post by Kari E. Hurt » Sat, 13 Jan 1996 04:00:00


?Signal 9 can't be catched. ^C is Signal 2 (SIGINT).

?You should at least also hook SIGHUP and SIGTERM. To see why you should
?hook SIGHUP, check man termio(7).

?Don't use signal 9 to kill processes unless the process doesn't terminate
?on a SIGTERM.

?  #include <signal.h>

?  void sighand (sig)
?  int sig;
?  {
?    /*
?        clean up and do an _exit(2) or do `signal (sig, sighand)' if you
[1]                                         ^^^^^^^^^^^^^^^^^^^^
?        want to continue. Check signal(2) for more info.
?    */
?  }

?  /* hook signal vectors. */
?  signal (SIGINT, sighand);
?  signal (SIGHUP, sighand);
?  signal (SIGTERM, sighand);

Warning: That [1] is Sys V:ism. BSD signal does not require re-establishing.

To get consistent behauviour, use POSIX's sigaction instead.

 
 
 

Catching "kill -9" and "^C"

Post by Dave Haverka » Sat, 20 Jan 1996 04:00:00


|> Can anyone show me how to catch kill -9 and ^C? I need do some shared memory cleanup before
|> my program actually exits.

Suggest you use "atexit()" to set up your exit handlers.  On sunOS you
will probably need to use "on_exit()".  Look at man page for usage.

If you still want to use a signal.  The terminate signal is the accepted
termination clean up signal.  Usually used between parent process and
child.

--
David Haverkamp

 
 
 

Catching "kill -9" and "^C"

Post by Stephen Bayn » Tue, 23 Jan 1996 04:00:00



: |> Can anyone show me how to catch kill -9 and ^C? I need do some shared memory cleanup before
: |> my program actually exits.

: Suggest you use "atexit()" to set up your exit handlers.  On sunOS you
: will probably need to use "on_exit()".  Look at man page for usage.

atexit functions are only called when one returns from main or calls exit.
If your program is killed by a signal then these functions are not called.
You will have to catch the signal (you handler can call then exit() ).

: If you still want to use a signal.  The terminate signal is the accepted
: termination clean up signal.  Usually used between parent process and
: child.

Yes you will need to catch SIGTERM and SIGHUP as well as SIGINT and SIGQUIT.
Depending on how robust you code is it may be sensible to catch SIGBUS,
SIGSEGV and SIGILL too.
If anything in you program calles abort then you will want to catch SIGABRT.

--

Philips Semiconductors Ltd
Southampton                                 My views are my own.
United Kingdom

 
 
 

1. Trapping (catching) "kill" and "kill -HUP"

Greetings,

        I have programmed a C/C++ cgi database. Due to the structure
of the database, it can use dynamic information such as a user defined
data file. In order for this to work, the pages that link to the
database are generated by a perl cgi script that does a read of the
data directory. The problem is that from the cgi generated page, if
anyone makes a call to the database  and then hits the back button
before the database has finished processing, httpd starts to execute
the perl page generating script and kills the database program leaving
all the data locked (note this isnt a problem when using static
htm(text) pages). How do I catch the "kill" and "kill -HUP" system
commands that may be sent to the database and allow my database to
clean up before it terminates? Any help would be greatly appreciated.
If you could please respond via email because I don't normally have
time to look through the news groups. Thanks.

Jamison Johnson
Technical Specialist
Leapfrog Technologies

2. Solaris network install server

3. GETSERVBYNAME()????????????????????"""""""""""""

4. how to enable PHP4 mcrypt

5. mount not killed with "kill -9"

6. Card services time-out on Strong ARM CF card

7. why doesn't "kill -9 -1" kill KDE control-panel

8. gigabit SX card

9. """"""""My SoundBlast 16 pnp isn't up yet""""""""""""

10. programming "less than" kill -9

11. Problems with using "kill -9"

12. Type "(", ")" and "{", "}" in X...

13. Trap "^C" "^Z" and "^\"