Page 1 of 1

Simple pid file check

Posted: Wed Feb 23, 2011 7:49 pm
by 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:

Code: Select all

(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.

Re: Simple pid file check

Posted: Wed Feb 23, 2011 10:39 pm
by 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:

Code: Select all

(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...

Re: Simple pid file check

Posted: Sat Feb 26, 2011 3:18 am
by kanen
So simple!

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

Perfect. Thanks!
cormullion wrote: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:

Code: Select all

(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...