🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: bt.unix
Article #3

Re: process group question

#3
From: Tim Oldham
Date: Fri, 09 Feb 1990 09:49
59 lines
3474 bytes
In article <1990Feb8.215909.16037@axion.bt.co.uk> mkirk@zaphod.axion.bt.co.uk writes:
>From article <1281@sun2.summer.bt.co.uk>, by francis@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@its.bt.co.uk or ...!ukc!axion!its!tjo
``Asking questions is the best way to get answers.'' --- Philip Marlowe.
Technical Details
Message-ID: <W566W@masalla.fulcrum.bt.co.uk>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!axion!masalla.fulcrum.bt.co.uk!beta.its.bt.co.uk!tjo
References: <1281@sun2.summer.bt.co.uk> <1990Feb8.215909.16037@axion.bt.co.uk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!axion!masalla.fulcrum.bt.co.uk!beta.its.bt.co.uk!tjo
From: tjo@its.bt.co.uk (Tim Oldham)
Newsgroups: bt.unix,bt.general,comp.unix.questions
Subject: Re: process group question
Message-ID: <W566W@masalla.fulcrum.bt.co.uk>
Date: 9 Feb 90 09:49:15 GMT
References: <1281@sun2.summer.bt.co.uk> <1990Feb8.215909.16037@axion.bt.co.uk>
Sender: igb@fulcrum.bt.co.uk (Ian G Batten)
Organization: BT Applied Systems, Birmingham, UK
Lines: 59