Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site rlgvax.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!rlgvax!guy
From: guy@rlgvax.UUCP (Guy Harris)
Newsgroups: net.unix,net.lang.c
Subject: Re: putting C programs in the background
Message-ID: <368@rlgvax.UUCP>
Date: Fri, 18-Jan-85 00:08:47 EST
Article-I.D.: rlgvax.368
Posted: Fri Jan 18 00:08:47 1985
Date-Received: Sat, 19-Jan-85 01:37:09 EST
References: <4600@cbscc.UUCP> <744@hou2h.UUCP>
Organization: CCI Office Systems Group, Reston, VA
Lines: 34
Xref: watmath net.unix:3350 net.lang.c:3937

> Can a program put itself into the background ???
> (SYS V R2)
> 
> 							Mark

1) This is a discussion of features of UNIX, not C; it belongs in net.unix/
INFO-UNIX, and I've moved it there - all followups should go there only.

2) "background" is an ill-defined term in UNIX.  If your definition of
a background process is one that the shell isn't waiting for, then the
sequence posted in the original article will do it quite nicely; several
daemons in 4.2BSD do exactly that when invoked, so that you can fire up
a new version of the daemon without getting screwed if you forget to put
an "&" after it.

If your definition of a background process is one that the shell isn't
waiting for *and* which isn't reading from or writing to a terminal, again
possible in any version of UNIX - just close all the file descriptors
referring to terminals, and possibly reopen them to refer to something else
(again, the aforementioned daemons do this).

If your definition of a background process is one that meets all the above
conditions and which is ignoring signals like SIGINT and SIGHUP, again
doable - just do a "signal" call to ignore them.

If your definition of a background process is one that meets the above
conditions and which isn't attached to a terminal, it's doable in 4.2BSD
by trying to open "/dev/tty" and, if it succeeds, doing a TIOCNOPGRP "ioctl"
on the resulting file descriptor and then closing the descriptor, and in
System III/System V Release * by doing a "setpgrp" system call.  (The
aforementioned daemons do the former.)

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy