process id from os.system
Michael Hudson
mwh21 at cam.ac.uk
Fri Jul 21 02:54:02 EDT 2000
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
More information about the Python-list
mailing list