1829590 Members
8725 Online
109992 Solutions
New Discussion

signals

 
khilari
Regular Advisor

signals

How does SIGTERM terminate a process in a orderly fashion? And how is it different to SIGHUP? Are there any other signal types recommended which would work better then SIGKILL which would just kill the process by force?
6 REPLIES 6
Patrick Wallek
Honored Contributor

Re: signals

Info on signals can be found from:

# man 5 signal

James R. Ferguson
Acclaimed Contributor

Re: signals

Hi:

In order for a signal to terminate a process in an orderly fashion, the signal must be catchable and it must be caught.

In the shell, arming a 'trap' constitutes the signal handler. When caught, the signal handler code runs and does *only* what you tell it to do. Different actions might be taken upon receipt of different signals. Removing temporary files, flushing file buffers, and releasing shared memory segments are common actions handled.

Some signals are *not* catchable. A kill -9 is the classic case. No signal handler that you write will run when your program receives a SIGKILL. Given that a SIGKILL cannot be caught (trapped) nothing can run to cleanup and hence things like shared memory segments can be left orphaned by your process.


Regards!

...JRF...
Pete Randall
Outstanding Contributor

Re: signals

A SIGHUP is a hangup signal, quite often used to get a daemon to re-read it's configuration file. A SIGKILL is a hard kill - it does not give a process a chance to shut down in an orderly fashion, release memory and resources, etc. A SIGTERM attempts to have things shut down gracefully, releasing resources owned by the process.


Pete

Pete
spex
Honored Contributor

Re: signals

> Are there any other signal types recommended which would work better then SIGKILL which would just kill the process by force?

SIGKILL (signum 9) is the "deadliest" signal of all.

PCS
Pete Randall
Outstanding Contributor

Re: signals

I should also mention that there is more information available in "man kill".


Pete

Pete
James R. Ferguson
Acclaimed Contributor

Re: signals

Hi (again):

I should add that there are times when a SIGKILL will have no effect. If a process is waiting on an I/O, or has already died but is waiting to be removed from the process table by its parent process (a "zombie"); then a 'kill -9' will have no effect.

Regards!

...JRF...