setpgrp question

Jonathan I. Kamens jik at athena.mit.edu
Mon Dec 25 07:42:50 AEST 1989


In article <6863 at cbnewsh.ATT.COM> skumar at cbnewsh.ATT.COM
(swaminathan.ravikumar) writes:
>If the following program is run you get the following error
>message:
>
>    "pg cannot reopen stdout"
>
>[asks what the purpose of setpgrp is]
>
>	#include <stdio.h>
>
>	main()
>	{
>	    setpgrp();
>	    system("pg /usr/tmp/junk");
>	}

  Well, since you're posting from AT&T, I assume you're using SysV of
some sort, rather than BSD :-).  Therefore, I don't know how
applicable my comments will be to your situation, since I don't know
how much of what I will describe below is shared by BSD and SysV.

  Our man page tty(4) has several sections applicable to this
question:

     ...

     Process Groups:

     Command processors such as csh(1) can arbitrate the terminal
     between different jobs by placing related jobs in a single
     process group and associating this process group with the
     terminal.  A terminal's associated process group may be set
     using the TIOCSPGRP ioctl(2):

          ioctl(fildes, TIOCSPGRP, &pgrp);

     or examined using TIOCGPGRP, which returns the current pro-
     cess group in pgrp.  The new terminal driver aids in this
     arbitration by restricting access to the terminal by
     processes which are not in the current process group; see
     ``Job Access Control'' below.

     ...

     Job Access Control:

     When using the new terminal driver, if a process which is
     not in the distinguished process group of its control termi-
     nal attempts to read from that terminal its process group is
     sent a SIGTTIN signal.  This signal normally causes the
     members of that process group to stop. If, however, the pro-
     cess is ignoring SIGTTIN, has SIGTTIN blocked, or is in the
     middle of process creation using vfork(2)), the read will
     return -1 and set errno to EIO.

     When using the new terminal driver with the LTOSTOP bit set
     in the local modes, a process is prohibited from writing on
     its control terminal if it is not in the distinguished pro-
     cess group for that terminal.  Processes which are blocking
     or ignoring SIGTTOU signals or which are in the middle of a
     vfork(2) are excepted and allowed to produce output.

  Also, I note that on our system, setpgrp has two arguments, not
none; is your setpgrp different, or are you doing something wrong (I
honestly don't know which it is.)?  From our man page:

     NAME
	  setpgrp - set process group

     SYNOPSIS
	  setpgrp(pid, pgrp)
	  int pid, pgrp;

  As for what the setpgrp call is used for, the man page for tty
points out the most common use, which is for command processors to
control who can get to the terminal and who can't.

  I hope this helps.

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710



More information about the Comp.unix.questions mailing list