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