How to determine if an instance of your program is already running?
Mike at kordik.net
Sun Dec 28 04:25:55 CET 2003
On Sat, 27 Dec 2003 03:42:15 -0800, David M. Wilson wrote:
> Mike <Mike at kordik.net> wrote...
>> Can I get a list of currently running processes?
> There is no portable way of doing it, however if you have a POSIX
> environment, you can parse the output of ps:
> def get_process_ids():
> output = 
> ps = os.popen('ps -o pid,command -C python')
> for line in ps:
> bits = line.lstrip()[:-1].split(' ')
> output.append( (int(bits), ' '.join(bits[1:])) )
> return output
> Don't hold me to this - I tested it on BSD and Linux, and as far as I
> know both the options I have used are portable.
Excellant. Thank you!
More information about the Python-list