monitoring/restarting an application
gnewsg at gmail.com
Fri Mar 6 15:02:49 CET 2009
On 5 Mar, 15:37, Ghirai <ghi... at ghirai.com> wrote:
> Hello list,
> I need to keep x number of instances of an external applications
> running, say /bin/x, but also kill and restart each one after y seconds.
> What would be the best way to do this (with python 2.5.x)?
> I'm thinking of having a list of running pids, then have a thread check
> if len(list) < x, and if it is, then start a new process (with
> os.spawnv?) and add it to the list.
> Also in the list i'd keep PIDs and some sort of started-timestamp, so i
> know which to kill.
> Does this sound reasonable, or is there an easier way?
Maybe you might want to take a look at psutil .
Rather than looking for PID->timestamp you can look for something else
like PID->cmdline or PID->executable_name.
for process in psutil.process_iter():
if (process.pid > 1000) and (process.name ==
# restart your process here
More information about the Python-list