process id from os.system

j vickroy jvickroy at sec.noaa.gov
Fri Jul 21 09:54:22 EDT 2000


Thanks very much for calling this to my attention.

Michael Hudson wrote:

> j vickroy <jvickroy at sec.noaa.gov> writes:
>
> > How can I obtain the process id for a program launched via
> >
> >   os.system (theProgram) ?
> >
> > I would like to do this portability (Unix, Windows).
> >
> > Presently on Unix, I'm getting the pid by parsing the output from:
> >
> >   "ps -ef | grep theProgram"
> >
> > but that seems messy and unreliable since "theProgram" may be truncated
> > in the output from ps.
>
> I think you should be able to use the os.spawn* functions in
> 1.6^H^H^H2.0 for this, eg:
>
> >>> os.spawnlp(os.P_NOWAIT,"xterm","xterm")
> 4722
>
> the spawn* functions are easy-ish to implement in terms of exec* &
> fork; look here:
>
> http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/python/dist/src/Lib/os.py?rev=1.35&content-type=text/x-cvsweb-markup&cvsroot=python
>
> HTH,
> Michael
>
> --
> 8. A programming language is low level when its programs require
>    attention to the irrelevant.
>   -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20000721/21697fcf/attachment.html>


More information about the Python-list mailing list