Simple pid file check

Started by kanen, February 23, 2011, 11:49:00 AM

Previous topic - Next topic

kanen

Hello all,



I am interested in testing for a running process and, if it is not running, restarting it.



Right now, I'm writing /tmp/app.pid files for everything I run. If I need to stop a running app, I call:


(destroy-pid (int (read-file "/tmp/app.pid")))

Which works, of course.



But, I want to test to see if the pid is actually running. Is there a clean, easy way to do this (something I am missing in unix.lsp, for example?)



Thanks.
. Kanen Flowers http://kanen.me[/url] .

cormullion

#1
Send 0 to a process using 'kill' - it will return true if the process is running (and accepting signals), nil if it isn't. So, after loading unix.lsp:


(kill pid 0)


will return true if PID is running. That's assuming you know the process ID .. :) If you don't know the PID, then you could use ps -ef | grep "name" to get it...

kanen

#2
So simple!



Thanks. That's exactly what I was missing. No idea why it didn't occur to me.



Perfect. Thanks!


Quote from: "cormullion"Send 0 to a process using 'kill' - it will return true if the process is running (and accepting signals), nil if it isn't. So, after loading unix.lsp:


(kill pid 0)


will return true if PID is running. That's assuming you know the process ID .. :) If you don't know the PID, then you could use ps -ef | grep "name" to get it...
. Kanen Flowers http://kanen.me[/url] .