Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My understanding is that a program that is associated with a BASH terminal will receive the SIGHUP signal if that terminal is closed. This usually will terminate the program.

I also know that you can use the nohup command along with the & symbol to run the program in the background, and disassociate it from the terminal so that the program is not terminated when the terminal closes (on log out.)

However, suppose a program is run normally without nohup, but is then suspended using Cntl-Z. If the program is then resumed in the background using the bg command, will it receive the SIGHUP signal on log out?

Or to put it another way: if I have a program which is already running, and I don't want to stop it but I'd like to log out, can I suspend it using Cntl-Z and run it in the background using bg? Or will the program be terminated when I log out?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You can use the disown command if you're using Bash.

From man bash:

If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP.

share|improve this answer

As Dennis says, in bash you can use disown to make the job not get SIGHUP when you close bash. BTW: you can also get the 'don't send SIGHUP' behavior if you run it with setsid not just nohup. setsid has the advantage of not messing with stdout and stderr like nohup does.

Some minor cleanup of your question tho:

My understanding is that a program that is associated with a BASH terminal

Not just bash, but ksh and zsh kill child processes with SIGHUP when the shells are closed too. It's pretty standard across shells. I'm too lazy to do real research and say 'all' do it, but I'm pretty safe in assuming they all do.

BASH terminal

Not bash terminal, but a bash shell. The terminal, well terminal emulator, is the window. Bash shell runs inside it.

will receive the SIGHUP signal if that terminal is closed. This usually will terminate the program.

Yes, by default you'll be terminated if you receive SIGHUP. Any app can chose to ignore this (then nothing happens) or can catch the signal and do something - log it, clean up, whatever. Daemon processes like webservers usually catch this and use it as an indicator to reread configuration files.

share|improve this answer

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.