TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:6767] Re: [SCALUG] Re: [TCLUG:6728] csh question



Troy A Johnson wrote:
> 
> I think there are versions of "ps" that will allow you to compare some
> process group id to some other process id and you will get a yes or no
> answer wether it is a background process, but the person I am asking this
> for has a version of "ps" that doesn't provide all the info needed.

Not sure, but....

>    By "you" I meant the background process (sorry for the ambiguity). It is
>    to answer a question for someone who is running a csh script and wants
>    it to behave one way when it is the foreground (get some input from the
>    user) and another way when it runs in the background. I "wrote" a C
>    utility that tests for a controlling tty (can I open /dev/tty?), but
>    just being in the background or foreground of a controlling process is
>    different. :-/

Try the following function:

 pid_t tcgetpgrp(int fildes);

I believe you can call it with /dev/tty (and yes, you can open
/dev/tty...of course, if the process isn't connected to a
terminal, the open will fail).  I haven't ever tried this
function.  I just looked it up in W. Richard Stevens' classic
book, Advanced Programming in the UNIX Environment.  I do believe
tcgetpgrp() is POSIX, so Linux should have it.

I'm not sure if you can find out directly, from within a shell
script, but you could certainly use it in a C program and call
that from the shell script.  I suppose csh might have a 'builtin'
command for checking fg/bg status, but I haven't seen it myself. 
Haven't looked, either.

Good luck!
John