I believe you are looking for os.getpid()
I apologize for providing that bit of incorrect info.
It looks to me as if Python 1.5 had os.process which might have done
what you wanted (although perhaps not in an OS-independent way). I
wonder why there isn't an OS-independent way to do that in Python now.
After having seen your message about tomcat.exe, I assume we are talking
just about Windows. ;-) This looks like an excellent way to deal with
processes on Windows:
# http://tgolden.sc.sabren.com/python/wmi_cookbook.html#running_processes
# List all running processes
import wmi
c = wmi.WMI ()
for process in c.Win32_Process ():
print process.ProcessId, process.Name
# List all running notepad processes
import wmi
c = wmi.WMI ()
for process in c.Win32_Process (name="notepad.exe"):
print process.ProcessId, process.Name
# Create and then destroy a new notepad process
import wmi
c = wmi.WMI ()
process_id, return_value = c.Win32_Process.Create
(CommandLine="notepad.exe")
for process in c.Win32_Process (ProcessId=process_id):
print process.ProcessId, process.Name
result = process.Terminate ()
李现民 wrote:
hi ,all
any one knows how to enumerate the current running processes , or
how to obtain a specific process by its name or process id. I know I
can do this in many programming languages , but how in python? any
one know?
Thanks for any guidance.
--
li xianmin
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
--
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED] | 402-438-8958 | http://www.ncee.net
Leading the Campaign for Economic and Financial Literacy
begin:vcard
fn:Shane Geiger
n:Geiger;Shane
org:National Council on Economic Education (NCEE)
adr:Suite 215;;201 N. 8th Street;Lincoln;NE;68508;United States
email;internet:[EMAIL PROTECTED]
title:IT Director
tel;work:402-438-8958
x-mozilla-html:FALSE
url:http://www.ncee.net
version:2.1
end:vcard
--
http://mail.python.org/mailman/listinfo/python-list