process group question

Neil Winton nwinton at iona.axion.bt.co.uk
Fri Feb 9 22:18:49 AEST 1990


In article <1281 at sun2.summer.bt.co.uk>, francis at summer.bt.co.uk (Francis
Tsui) writes:
> Can someone please tell me what a process group leader does,
> especially with regards to terminals, and how you can make a 
> process a process group leader. I am using SunOS4.0.

Ok, I'll give it a stab.

First, the concept of `process group' is itself fairly simple and self
explanatory -- it's a group of processes :-)  The main question is: what
can you do with such a group?  The simplest answer to this is that you
can send a simultaneous (or as near as you can manage on a time-sharing
system) signal to all the members of the group.  This is done by using
the `kill()' function with negative pid, the absolute value of which
is interpreted as the process group id.  This functionality is common to
all flavours of UNIX systems.

Right, the next question is `how do you find out the process group id?'
This is where things start going a little awry ...  On System V (and
POSIX) you use the call `getpgrp()' with no arguments to determine the
pgid of the calling process.  On BSD-based systems you can specify an
argument to find the pgid of a specific process, or use 0 if you want
to find it for the current process.  Under SunOS, being a mixture, you
can take your pick ...

>From here on in, things start to diverge quite rapidly -- and that is
why quite a bit of work has been done on this area in POSIX to provide
a clear, common set of functionality.  The basic problem is to do with
`job control'.

To create a new process group under System V you use the `setpgrp()'
call with no arguments.  This places the calling process into a new
process group, whose pgid is the same as the pid.  (The function also
returns the pgid).  The process is then the `process group leader',
that is, all children of this process will be in the same process
group and will have the same pgid.  There is no other particular
connotation to `leader' in this respect.  Changing process groups
makes a process immune from terminal interrupt signals (SIGHUP,
SIGINT, SIGQUIT) but does not disassociate a process from a terminal.

Under BSD (and thus SunOS), the setpgrp() call has two arguments, a
`pid' and a `pgid'.  This call makes `pid' a member of process group
`pgid'.  When a new process group is created it will be blocked from
terminal input and output (it is a `background' process) if it does
not have the same process group as the terminal.  The terminal process
group can be manipulated by using the TIOCGPGRP and TIOCSPGRP ioctl()
calls.  Jobs can therefore be moved between foreground and background
by manipulating either their process group or that of the terminal.
Under System V the process group of the terminal is taken from the
process group of the first process group leader to be attached to it.

POSIX has basically similar functionality to BSD but implemented via
`session ids'.  I can try and give details if you want ...

	I hope this helps,

		Neil

E-Mail (UUCP)  NWinton at axion.bt.co.uk (...!uunet!mcvax!axion.bt.co.uk!nwinton)
Organisation   British Telecom Research Laboratories (RT3134)
Snail Mail     310 SSTF, BTRL, Martlesham Heath, IPSWICH IP5 7RE, UK
Telephone      +44 473 646079 (or +44 473 643210)
*** This line intentionally left justified ***



More information about the Comp.unix.questions mailing list