[Gllug] Starting a daemon

Nix nix at esperi.org.uk
Tue Jan 4 23:17:37 UTC 2011


On 30 Dec 2010, Richard W. M. Jones spake thusly:
>             Having said that I've never understood if there is a
> difference between "session" and "process group" and the man page
> doesn't explain it very well either.

A session is a collection of process groups, so setsid() does indeed put
your process in its own process (group (making it the process group
leader in the process). APUE, as ever, explains this very clearly :)

Stevens's example of the difference is this:

proc1 | proc2 & proc3 | proc4 | proc5

In this example, there is one session (the session leader being the
shell). There are three process groups, one being the login shell, one
being proc1 | proc2 (process group leader proc1), the other being
proc3 | proc4 | proc5 (process group leader proc3).

One way you can tell this is that you can send signals to any of these
process groups independently (e.g SIGINT) but that they all necessarily
have the same controlling TTY (as this is a property of the *session*).


As is true of so many things in this general area, the API is rather
inconsistent and confusing: e.g. you can only become a session leader if
you are *not* already a process group leader: one evades this by
fork()ing and having the parent die and the child call setsid().


Terminal emulation and keyboard signal dispatch in Unix is powerful but
it's a sodding mess as well. It *really* should have been possible to
implement without adding *so* many kernel-level concepts. Typical BSD
(but in that, much better than the nightmarish crap which was typical
SysV of the time: can you say 'SysVIPC'?)
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list