HELP - Background jobs in csh

Chris Torek chris at umcp-cs.UUCP
Thu Apr 11 08:06:48 AEST 1985


To find out whether your program is in the foreground:

	#include <sys/ioctl.h>

	foregroundp()
	{
		int tpgrp;	/* short in 4.1, int in 4.2 */

		if (ioctl(0, TIOCGPGRP, &tpgrp))
			return 0;
		return tpgrp == getpgrp(0);
	}

Unfortunately, the program's status can change between the ioctl
and the getpgrp.  If you don't mind races, the above is sufficient.
If you mind them, then you have to hold SIGTSTP, SIGTTIN, and
SIGTTOU until you know what you're going to do.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.unix.wizards mailing list