Entry
Getting process ID
Jul 1st, 2008 11:29
sheana krat, Nathan Wallace, Hans Nowak, Snippet 382, Moshe Zadka
"""
Packages: operating_systems.unix
"""
"""
> The portable way to do it (in UN*X, I mean) is to run a script and get
> the output (via pipes), something like:
>
> #!/bin/sh
> ps -ef | grep "$1" | grep -v grep | awk '{ print $1 }'
And in 100% Pure Python(tm):
"""
#!/usr/bin/env python
import os, string
lines = os.popen("ps -ef").readlines()
processes = []
for line in line:
if string.find(line, sys.argv[1]) != -1:
processes.append(string.atoi(string.split(line)[0]))
for process in processes:
os.kill(process)
http://www.indianhandicraftsexporters.com
http://www.topgiftsideas.com
http://www.eindianweddingcards.com