Sujet : Re: nohup Versus setsid
De : nn.throttle (at) *nospam* xoxy.net (Helmut Waitzmann)
Groupes : comp.unix.shellDate : 13. Sep 2024, 18:00:45
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <83wmjf1oaq.fsf@helmutwaitzmann.news.arcor.de>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Lawrence D'Oliveiro <
ldo@nz.invalid>:
It has long seemed to me that nohup(1) was an old, hacky way of doing what can be done more elegantly using setsid(1). Compare the docs for yourself <https://manpages.debian.org/1/nohup.1.en.html> vs <https://manpages.debian.org/1/setsid.1.en.html>, and tell me why we still need nohup when we have setsid? >
Because there is a real difference between both of them. "nohup" makes the invoked command immune to the HUP signal but lets it remain in its terminal session, i. e. the command to be run will not lose its controlling terminal. Thus the other job control signals like TSTP, INT, and QUIT sent by the terminal driver to the command may have their effects. Also, the HUP signal will be ignored regardless of its origin (terminal driver as well as the "kill(2)" system call). If, on the other hand, you use "setsid", the command to be run will not be made immune to any of the job control signals, i. e. any job control signal sent to the command to be run by means of the kill(2) system call will have its effect. Also, as the command to be run will leave the terminal session and thus lose the controlling terminal of the invoker, it won't be affected by any job control signal sent by the terminal driver of the invoker's controlling terminal, for example when typing the interrupt, suspend or quit key on the keyboard no signal will reach the command to be invoked.