[net.unix] UNIX and/or Gosling Emacs problem.

shaji@sbcs.UUCP (Shaji Bhaskar) (08/27/85)

I have a problem with process handling in Gosling Emacs (V2.01).
running under UNIX 4.2.  What I need to do is to leave a process
running in the background even after Emacs exits.  I start the
process using "start-filtered-process".  I send the process something
on its standard input using a "region-to-process", send an EOF to the
process, and then exit emacs.  However, Emacs kills my process if it
is still running.  Setting the variable "silently-kill-processes" to
0 is supposed to do the trick.  However, Emacs appears to be sending
a SIGHUP to its children regardless.  I do not know whether the
problem is with UNIX pseudo ttys or an EMACS bug, so I am posting
this to both net.unix and net.emacs.  

I have tried explicitly ignoring the signal in my child process, but
it is possible that the process receives the SIGHUP before it does a
signal(SIGHUP, SIG_IGN), leaving me with a dead pocess when I think I
have a running process.  I need a way around this problem that is
elegant.  

Is this a well-known problem?  Are there any easy fixes?  I do not
want to hack the source of Emacs unless it is to remove the bug (if
any) that causes this signal to be sent.  In particular, I dont want
to hack Emacs to create children that ignore SIGHUP, unless the
problem is caused by the operating system's process handling
mechanism, but am willing to try it as a last-ditch measure.

* Yet another reason for switching to GNUEmacs, maybe? :-) *

Shaji Bhaskar, Dept of Comp. Sc., SUNY@Stony Brook.
UUCP : {allegra, philabs}!shaji
CSnet : shaji@sbcs.csnet

chris@umcp-cs.UUCP (Chris Torek) (08/29/85)

If you want your program to run "in the background", it should do its
own forking *and* close fd's 0, 1, and 2 *and* (to be nice) it should
probably give up its control terminal as well.

Note that I do not mean "background" in the sense the C shell uses.

#include <stdio.h>
#include <sys/ioctl.h>

/*
 * Continue running as a completely detached process.
 */
backgroundify()
{
	register int pid, tt;

	fflush(stdout);		/* clean up */
	fflush(stderr);
	if ((pid = vfork()) < 0) {
		perror("backgroundify: fork");
		return (-1);
	}
	if (pid)		/* parent */
		exit(0);
	if ((tt = open("/dev/tty", 2)) >= 0) {
		(void) ioctl(tt, TIOCNOTTY, (char *)0);
		(void) close(tt);
	}
	(void) close(0);
	(void) close(1);
	(void) close(2);
	return (0);
}
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@maryland