Hello All,
I was looking into creating a script that would be used only to start a Daemon and create a lock file...
F.Y.I. It's for Nagios' NRPE Daemon Plugin...
Anyway when I run the command to start the Daemon (below):
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
And try to get the PID of that Command just ran by adding this to the end of that line above:
...-c nrpe.cfg & echo $!
The PID it prints out is NOT the PID of the NRPE Daemon. Am I not using the "echo $!" correctly...?
On one of the boxes im trying this on, which is SLES 11.1 (Bash), the PID it prints out is one number
less then what the actual PID of the Daemon is.
For Example:
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d & echo $!
[1] 27329
27329
# ps -ef | grep [/]usr/local/nagios/bin/nrpe
nagios 27330 1 0 15:20 ? 00:00:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
I thought maybe it was just a coincidence, so I tried it a few more times, and still it does the same thing.
So I figured I would just implement this one and just subtract 1 from the PID it gives me to
get the real PID, but I then tried this same thing on an AIX server and the actual PID was completely random. So
I decided not to do that (probably wouldn't have been a good idea anyway)...
Does anyone know what I'm doing wrong, or if there is a better way to get this PID (without doing the 'ps -ef | grep ...')..??
Any thoughts would be great!
Thanks in Advance,
Matt