zshで`nohup watch`が機能するようにするには`setopt nohup`が必要なのはなぜですか?

zshで`nohup watch`が機能するようにするには`setopt nohup`が必要なのはなぜですか?

zshでは、setopt nohupnohupが次のように動作するようにする必要があるようです:

# nohup does not work without setopt nohup
➜  /tmp  zsh
➜  /tmp  nohup watch ls &
[1] 31556
nohup: ignoring input and appending output to ‘nohup.out’                                                                                                                                                   
➜  /tmp  exit
zsh: you have running jobs.
➜  /tmp  exit
zsh: warning: 1 jobs SIGHUPed
➜  /tmp  ps -fp 31556
UID        PID  PPID  C STIME TTY          TIME CMD

# It works well with setopt nohup
➜  /tmp  zsh
➜  /tmp  setopt nohup
➜  /tmp  nohup watch ls &
[1] 31216
nohup: ignoring input and appending output to ‘nohup.out’                                                                                                                                               
➜  /tmp  exit
zsh: you have running jobs.
➜  /tmp  exit
➜  /tmp  ps -fp 31216
UID        PID  PPID  C STIME TTY          TIME CMD
nori     31216     1  0 19:00 pts/6    00:00:00 watch ls

zshにはなぜ必要ですsetopt nohupが、bashには必要ありませんか?

ベストアンサー1

nohup取り付けられた信号ハンドラを置き換える信号ハンドラが取り付けられているため、watch無効です。watchSIGHUPnohup

nohupSIGHUPシグナルが無視されるようにするシグナルハンドラを設定し、実行を要求されたSIG_IGNプログラムを実行するように動作します。これは、起動時に信号が設定された方法で設定されたターゲットプログラムに対してうまく機能します。これは基本的にプログラムが信号にまったく注意を払わないことを意味します。ただしwatch、他のシグナル用のシグナルハンドラをインストールしてくださいSIGHUP(終了する前に端末設定の変更を元に戻すため)。

おすすめ記事