Simple pid file check

Q&A's, tips, howto's
Locked
kanen
Posts: 145
Joined: Thu Mar 25, 2010 6:24 pm
Contact:

Simple pid file check

Post 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.
. Kanen Flowers http://kanen.me .

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: Simple pid file check

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

kanen
Posts: 145
Joined: Thu Mar 25, 2010 6:24 pm
Contact:

Re: Simple pid file check

Post 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...
. Kanen Flowers http://kanen.me .

Locked