Determining if program executing in shell background?

Kevin Perrott kevin at kevsplace.net
Fri Mar 28 22:17:23 EST 2003


Works as advertised...

FYI... except getpid doesn't take an argument

THANKS!

"Donn Cave" <donn at u.washington.edu> wrote in message
news:b62mau$2aoi$1 at nntp6.u.washington.edu...
> Quoth "Kevin Perrott" <kevin at riversidehonda.com>:
> | I'm trying to find a function that will tell me if a pyton program is
> | executing in the background when launched using the:
> |
> | <program name> &
> |
> | shell syntax.
>
> You might try this:
>
> if os.tcgetpgrp(0) == os.getpid(0):
> print 'foreground'
> else:
> print 'background'
>
> This is basically asking if the current process is the process leader
> of the foreground process group for tty device unit 0 (standard input.)
>
> Donn Cave, donn at u.washington.edu






More information about the Python-list mailing list