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.

I'm running a command that I now realize I'd like to leave running after I close my SSH session. I didn't start it with a & argument, but I have put it in the background (CTRL-z, bg). Now I'm trying to make it keep going after I disconnect. That's what disown -h is for, right? I've tried disown -h and disown -h 1 (jobs shows my job as #1), and I get

disown: job not found: -h

Why is disown taking "-h" as a jobspec rather than an argument? I'm in zsh, if that matters.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

bash, zsh and ksh93 are the shells that have a disown command. Of the three, bash is the only one that supports a h option. Without -h it emultates zsh behavior (remove from the job table), while with -h it emulates ksh93 behavior (will no send it a SIGHUP upon exit, but doesn't remove it from the job table so you can still bg or fg or kill it).

You could emulate that behavior with zsh, by doing:

typeset -A nohup
trap 'disown %${(k)^nohup}' EXIT
trap 'for i (${(k)nohup}) (($+jobstate[i])) || unset "nohup[$i]"' CHLD

So the nohup associative array holds the list of jobs that are not to be sent a SIGHUP upon exit. So, instead of disown -h %1, you'd write nohup[1]=.

See also setopt nohup to not send SIGHUP to any job upon exit.

share|improve this answer
    
First, what's the %1 in your example, and @mrb's answer? I think just "1" by itself worked (as in, disown 1) when I tried it. Second, is the option you're referring to NO_HUP? I found HUP in the zshoptions man page, and I guess you can tack on NO_ to turn stuff off? –  Coderer Nov 30 '12 at 8:28
    
The % is for job specifications. It's not needed for fg, bg or disown, but is for kill, so I got into the habit of using it whenever I refer to a job as opposed to a process ID. Yes setopt noopt is the same as unsetopt opt and underscores are ignored. It is documented. –  Stéphane Chazelas Nov 30 '12 at 10:44

disown on its own is sufficient to let the program keep running after you disconnect:

$ command_running_forever
^Z
zsh: suspended  command_running_forever
$ bg
[1]  + continued  command_running_forever
$ jobs
[1]  + running    command_running_forever
$ disown %1
$ logout

disown -h uses a bash argument which causes the job to remain on the job table and does not receive a SIGHUP when bash receives a SIGHUP (according to bash's help disown). This argument is not available with zsh.

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.