putting C programs in the background
Guy Harris
guy at rlgvax.UUCP
Fri Jan 18 15:08:47 AEST 1985
> 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
More information about the Comp.unix
mailing list