Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10 5/3/83; site bbncca.ARPA
Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!ihnp4!bbncca!keesan
From: keesan@bbncca.ARPA (Morris M. Keesan)
Newsgroups: net.lang.c
Subject: Re: putting C programs in the background
Message-ID: <1269@bbncca.ARPA>
Date: Fri, 18-Jan-85 11:20:26 EST
Article-I.D.: bbncca.1269
Posted: Fri Jan 18 11:20:26 1985
Date-Received: Sat, 19-Jan-85 01:27:39 EST
References: <4600@cbscc.UUCP>
Organization: Bolt, Beranek and Newman, Cambridge, Ma.
Lines: 34

-----------------------------
>To put a C program in the background (not from the shell)
>try the following:
>
>	 if (fork() != 0) exit(0);
>
>Simple yes.  Obvious, well maybe.  And don't forget to
>setup those signal handlers and file descriptor just right.
>
>			 Larry Cipriani
>			 cbscc!cbsch!lvc

Almost.  Actually, a little too simple.
Better:

	pid = fork();
	if( pid < 0 )
	{
	    /* Print error message */
	    exit(1);
	}
	else if( pid > 0 )
	{
	    /* parent */
	    exit(0);
	}
	/* else pid == 0, this is the child.  Continue */

The correct thing to do about signals, to match what the shell does when it
puts something in background, is to ignore SIGINT and SIGQUIT.
-- 
			    Morris M. Keesan
			    {decvax,linus,ihnp4,wivax,wjh12,ima}!bbncca!keesan
			    keesan @ BBN-UNIX.ARPA