- 论坛徽章:
- 0
|
I copied from other place and it's a very useful tool.
=================================================
#!/usr/bin/env python
import os
import sys
import re
if len(sys.argv) != 2:
#print >> sys.stderr, "Provide one (and one only) pattern to match."
sys.exit(1)
ps = os.popen('ps -e')
ps.readline() #-- To eliminate initial line
for line in ps:
try:
match = re.search(r"%s" % (sys.argv[1],), line, re.IGNORECASE)
except re.error:
match = None
sys.exit(1)
if match != None:
print re.search(r"^\s*?(\d+)(?=\s)", line).group(1) |
|