process group question
Tim Oldham
tjo at its.bt.co.uk
Fri Feb 9 20:49:15 AEST 1990
In article <1990Feb8.215909.16037 at axion.bt.co.uk> mkirk at zaphod.axion.bt.co.uk writes:
>From article <1281 at sun2.summer.bt.co.uk>, by francis at summer.bt.co.uk (Francis Tsui):
>> 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.
>>
>
>Process groups are normally manipulated by shells and used to
>associated together groups of processes. I have never had to play with
>them, but I think that the following is correct in principle.
>
>Process groups are generally used by job contol shells such as the csh
>and ksh on systems that provide kernel support for job control (BSD,
>System V Release 4, etc).
>
>Each "job" is put in its own process group. Thus all the processes in
>the group can receive the same signals. This is necessary to support
>transferring jobs between background and foreground, and for killing
>entire jobs.
To expand on this a bit:
A process group is a set of processes that logically linked by having
a common process group number. Thus, several processes have the same
process group number if they are in the same process group. Process
groups are special in that you can send a signal to all the processes
within a process group. You do this by specifying a process group id to
killpg(2). Also note that some kill(2) uses are variants on killpg().
If you read the manual page for kill(2), you'll see the difference to
the SysV.
The terminal has (may have) a process group associated with it. If a process
which is supposed to be able to write to the terminal but is not
currently associated with it tries to write to the terminal, it will
be sent SIGTTOU. Similarly for SIGTTIN, input from the terminal. This is
how the shell manages background jobs that try to write
to the terminal; it makes all the processes in a background job
into a process group, and disassociates that group from the terminal.
If the shell later sees that the processes have been stopped (they've
received SIGTTOU or SIGTTIN) it can then print a message out to tell
you that they tried to read from or write to the terminal. If you
then bring the commands into the foreground with fg, it can reassociate the
process group with the terminal, and use killpg(group, SIGCONT)
to tell them to continue.
A similar thing happens when you put a job into the background. You
stop the job with ctrl-Z which sends SIGSTOP to the process group. When
type `bg' the shell disassociates the group from the terminal and
uses killpg(group, SIGCONT) to start them again.
Note that the ioctl to (dis)associate the processes with the terminal
is TIOCSPGRP - you do the (dis)association on a process group, not
on a process.
Tim.
--
Tim Oldham, BT Applied Systems. tjo at its.bt.co.uk or ...!ukc!axion!its!tjo
``Asking questions is the best way to get answers.'' --- Philip Marlowe.
More information about the Comp.unix.questions
mailing list