Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a way to find out what will program do when it receives kill signal HUP?
Without simply running the command ofc :D

For example,
killall -HUP pppd will restart pppd
killall -HUP firefox will just kill firefox

share|improve this question
add comment

2 Answers

up vote 12 down vote accepted

Read its documentation. That's the only way. As Keith already wrote, the original meaning of SIGHUP was that the user had lost access to the program, and so interactive programs should die. Daemons — programs that don't interact directly with the user — have no need for this behavior and instead often reload their configuration files when they receive SIGHUP. But these are just conventions.

If you have the source, you can read that, too. Or if you only have the binary, you can try disassembling it, look for sigaction calls that set up a signal handler for SIGHUP, and try to figure out what those signal handlers are doing. It'll be easier arranging not to send SIGHUP to that program in the first place.

At any point in time, a given process is in one of three states with respect to a particular signal: ignoring it, performing the default action or running a custom handler. Many unices allow you to see the signal mask of a process with ps, e.g. with ps s on Linux. That can tell you if the process is ignoring the signal or will die instantly on SIGHUP, but if the process has set a handler you can't tell what the handler does.

share|improve this answer
    
SIGHUP goes back to the days of dial-up modems. It signaled a Hang-UP of the modem connection. It still applies to a dropped connections, but these days its rarely a hang-up that causes the connection to be dropped.P –  BillThor Jun 24 '11 at 23:33
    
@bill True, but an SSH session will also SIGHUP it's child process if it loses its client connection. –  Keith Jun 25 '11 at 0:10
    
@Keith: That's why I indicated that it applies to dropped connections, and is rarely caused by hang-ups anymore. It would be confusing at this point to change its name to something related to disconnects, such as SIGDCN. –  BillThor Jun 25 '11 at 0:12
add comment

The default action is to terminate the process on SIGHUP. See man 7 signal for more details. But programs can trap it and do whatever they want. Since deamon processes are never supposed to exit they commonly use SIGHUP for other purposes, such as reinitializing themselves (as pppd does). Firefox keeps the default action.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.