Determining if program executing in shell background?

lucio lucio at movilogic.com
Fri Mar 28 17:36:37 EST 2003


sik0fewl wrote:

> Kevin Perrott wrote:
>
>> I'm VERY new to python programming so please be gentle.
>>
>> 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.
>
>
> If it's not a problem you could run the program having stdout and 
> stderr pipe to /dev/null and put to background:
>
> program.py 2>&1 >/dev/null &
>
> or have a -D switch that changes sys.stdout and sys.stderr to a custom 
> class that does nothing.
>
> I'm honestly not sure if there is a better way to do this, but if this 
> is being run automatically, instead of by the user either of the above 
> solutions should be fine.


Maybe the trick is to try to read from stdin, and catch SIGSTOP..

check out the following shell output
-------------------------------- 8<---------
lucio at patoruzu:~/a$ vi &
[1] 31094
lucio at patoruzu:~/a$

[1]+  Stopped                 vi
lucio at patoruzu:~/a$
------------------------------------------

When bash 'stopped' vi, i belive it sent some singnal.

HTH,

Lucio.







More information about the Python-list mailing list