am I in background?

Joseph S. D. Yao jsdy at hadron.UUCP
Sun Nov 17 07:35:19 AEST 1985


In article <129 at wgivax.UUCP> mo at wgivax.UUCP (Michael O'Shea) writes:
>On a 4.2 system, is there any reliable way in which a c-program can determine
>from within itself if it is running in background and/or has its input and/or
>output redirected (from/into a file or through a pipe)?

It sounds (from text not quoted here) like what you really want to know
is whether the standard input is the user's terminal.  Phrased that
way, you've prob'ly already realised the easy way:

#define STDIN	0

	if (isatty(STDIN)) ...

(See man 3 ttyname on BSD4.2; should be similar on all other Unices.)
-- 

	Joe Yao		hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}



More information about the Comp.unix.wizards mailing list