Sujet : Re: nohup Versus setsid
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.shellDate : 12. Sep 2024, 13:01:37
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vbul72$89jc$1@dont-email.me>
References : 1 2
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 12.09.2024 13:37, Kenny McCormack wrote:
In article <vbtqcd$2sce$1@dont-email.me>,
Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
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 [...], and tell me why we still need nohup when we have setsid?
I don't know the details, but the descriptions look quite different...
nohup - run a command immune to hangups, with output to a non-tty
setsid - run a program in a new session
First, I do get what you're saying - and I've both A) Used setsid(2) a lot
over the years so am familiar with it and B) Always thought that nohup(1)
was old and crusty. I cringe whenever I hear people recommend it in help
groups nowadays.
Yes it's old; existing almost from Unix' beginning (at least Version 7).
But I used nohup a couple times, to have the function described above.
(I've never used setsid, never needed it, didn't even know it exists.)
That said, it is kind of apples-to-oranges comparison. nohup(1) is more of
a command, while setsid(1) is really just a thin wrapper around the system
call. According to the man page, nohup(1) does a lot of things, including
setting up logging and so on; there is no underlying system call. OTOH, to
understand setsid(1), you really have to understand the underlying system
call - and that system call is not simple. It (setsid(2)) is kind of a
"bigger/better" version of setpgrp() and it has some interesting
restrictions on its use. In a way, it could be said that both sessions and
process groups were only implemented to support shell job control, and this
is kind of a funny thing, since shell job control is now sort of thought of
as an anachronism (I still use it, but I seem to be in some kind of minority).
Well, count me to the minority.
But why are you saying that "job control is now sort of thought of as
an anachronism"?
So, despite what I said 2 paragraphs ago, nohup(1) may be better as a
recommendation to the newbie.
A non-technical but more fundamental answer can be that nohup is POSIX
standard while the other is not (with all consequences for the general
case, portability, etc.).
Janis