nohup e disown -h não são exatamente a mesma coisa.
Com disown , um processo é removido da lista de trabalhos no shell interativo atual. Executar jobs após iniciar um processo de segundo plano e executar disown não mostrará esse processo como um trabalho no shell. Um trabalho rejeitado não receberá um HUP do shell quando sair (mas veja a nota no final).
Com disown -h , o trabalho não é removido da lista de tarefas, mas o shell não envia um sinal HUP para ele se ele sair (mas veja a nota no final).
O utilitário nohup ignora o sinal HUP e inicia o utilitário fornecido. O utilitário herda a máscara de sinal de nohup e, portanto, também ignorará o sinal HUP . Quando o shell é encerrado, o processo permanece como um processo filho de nohup (e nohup é representado novamente em init ).
A diferença é que o processo começou com nohup ignores HUP , independentemente de quem envia o sinal. Os processos rejeitados simplesmente não são enviados a HUP signal pelo shell , mas ainda podem ser enviados o sinal de por ex. kill -s HUP <pid> e não vai ignorar isso.
Observe que HUP é enviado apenas para os trabalhos de um shell se
- o shell é um shell de login e a opção
huponexitshell está definida ou - o próprio shell recebe um sinal
HUP.
Bits relevantes do manual bash (minha ênfase):
SIGNALS
[...]
The shell exits by default upon receipt of a
SIGHUP. Before exiting, an interactive shell resends theSIGHUPto all jobs, running or stopped. Stopped jobs are sentSIGCONTto ensure that they receive theSIGHUP. To prevent the shell from sending the signal to a particular job, it should be removed from the jobs table with thedisownbuiltin (seeSHELL BUILTIN COMMANDSbelow) or marked to not receiveSIGHUPusingdisown -h.If the
huponexitshell option has been set withshopt,bashsends aSIGHUPto all jobs when an interactive login shell exits.
disown [-ar] [-h] [jobspec ... | pid ... ]Without options, remove each
jobspecfrom the table of active jobs. [...] If the-hoption is given, eachjobspecis not removed from the table, but is marked so thatSIGHUPis not sent to the job if the shell receives aSIGHUP. [...]
Relacionados: