🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.sys5
Article #122

Re: SysVR3.2 Setpgrp behaviour

#122
From: Lloyd Kremer
Date: Mon, 16 Oct 1989 15:56
45 lines
1719 bytes
In article <253664A4.20995@ateng.com> chip@ateng.com (Chip Salzenberg) writes:

>You should also do another fork() AFTER the setpgrp().  Otherwise, the child
>process remains a process group leader.  And if a process group leader
>without a controlling tty opens a tty that no other process has open at the
>time [inhale], then that tty becomes the process's controlling tty.  So the
>child must fork() again; then the grandchild process is a safe daemon.
>
>Finally:
>
>	/*
>	 * Daemon code.
>	 * Insert error checking to taste.
>	 */
>
>	if (fork() != 0)
>		exit(0);
>	setpgrp();
>	if (fork() != 0)
>		exit(0);
>
>	/*
>	 * And away we go...
>	 */


Do you need two forks?  Wouldn't the "second" fork alone be sufficient?

Example:
	setpgrp();  /* original parent divorces controlling tty and
		       becomes process group leader */
	close(0);
	close(1);
	close(2);  /* sure, why not? */
	if(fork() != 0)
		exit(0);  /* death of parent backgrounds the process */
	/* child process will be non-process-group-leader */

	/* And away we go... */

-- 
					Lloyd Kremer
					...!uunet!xanth!kremer
					Have terminal...will hack!
Technical Details
Message-ID: <10199@xanth.cs.odu.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uwm.edu!gem.mps.ohio-state.edu!uakari.primate.wisc.edu!xanth!kremer
References: <1970@oid.UUCP> <1273@virtech.UUCP> <253664A4.20995@ateng.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uwm.edu!gem.mps.ohio-state.edu!uakari.primate.wisc.edu!xanth!kremer
From: kremer@cs.odu.edu (Lloyd Kremer)
Newsgroups: comp.bugs.sys5,comp.unix.wizards
Subject: Re: SysVR3.2 Setpgrp behaviour
Summary: Wouldn't one fork be enough?
Message-ID: <10199@xanth.cs.odu.edu>
Date: 16 Oct 89 15:56:09 GMT
References: <1970@oid.UUCP> <1273@virtech.UUCP> <253664A4.20995@ateng.com>
Followup-To: comp.bugs.sys5
Organization: Old Dominion University, Norfolk, Va.
Lines: 45