Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: john@iastate.edu (John Hascall)
Subject: Bug?  Control Terminal vs. Process Group
Date: 1995/07/11	[thread overview]
Message-ID: <3tud8e$nos@news.iastate.edu> (raw)

The common practice in daemon writing (as, for example, in Stevens'
_Unix Network Programming_) seems to be to change your process group
and then drop your control terminal.

I noticed that the CERN (3.0) httpd server, which follows this paradigm,
was failing in its attempt to kill its children upon receipt of SIGTERM.

I traced this to its process group being zero.  It appears that, at least
under Ultrix v4.3a, that dropping the control terminal sets the process
group to zero (see example program and output below).

My question is:
     * Is this a bug in Ultrix?
     * Is this just Ultrix choosing one of several alternative behaviours?
     * Is this standard behaviour and _Unix Network Programming_ etc.
       are in error?

John
----------------------------------- results -----------------------------------
% pgrp
process id is 26398                       (parent which exits)
process id is 26399                       (child)
process group is 26398
set process group returns ok
process group is 26399
drop control tty returns ok               <=== doing this
process group is 0                        <=== results in this?!?
set process group returns ok
process group is 26399
----------------------------------- pgrp.c ------------------------------------
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>

char *  ok[] = {"error", "ok"};
#define OK(n)   ok[n+1]

int main(argc, argv)
	int	argc;
	char **	argv;
{
	int	fd;

	printf("process id is %u\n", getpid());
	if (fork() != 0) _exit(0);
	printf("process id is %u\n", getpid());
	printf("process group is %u\n", getpgrp(0));
	printf("set process group returns %s\n", OK(setpgrp(0, getpid())));
	printf("process group is %u\n", getpgrp(0));
	fd = open("/dev/tty", O_RDWR);
	printf("drop control tty returns %s\n",
	    OK(ioctl(fd, TIOCNOTTY, (char*)NULL)));
	close(fd);
	printf("process group is %u\n", getpgrp(0));
	printf("set process group returns %s\n", OK(setpgrp(0, getpid())));
	printf("process group is %u\n", getpgrp(0));
	return (0);
}
-- 
John Hascall                ``An ill-chosen word is the fool's messenger.''
Moderator, comp.unix.wizards
Systems Software Engineer, ISU Comp Center + Ames, IA  50011 + 515/294-9551
<a href="http://www.cc.iastate.edu/staff/systems/john/">My Homepage</a>



                 reply	other threads:[~1995-07-11  4:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox