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.
Best Answer
bash
,zsh
andksh93
are the shells that have adisown
command. Of the three,bash
is the only one that supports ah
option. Without-h
it emultateszsh
behavior (remove from the job table), while with-h
it emulatesksh93
behavior (will not send it a SIGHUP upon exit, but doesn't remove it from the job table so you can stillbg
orfg
or kill it).You could emulate that behavior with zsh, by doing:
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 writenohup[1]=
.See also
setopt nohup
to not send SIGHUP to any job upon exit.