pidofproc function in functions script

dennisjperkins at dennisjperkins at
Wed Jul 18 12:32:55 PDT 2007

> >     # If a pidfile was not passed, look for one in /var/run.
> >     base=${process##*/}
> >     ${pidfile:=/var/run/$} 2> /dev/null
> I would sort of like to kill this section since I think it's kind of
> evil to "guess" a pidfile when it wasn't specifically asked for. This
> would change existing behavior for current bootscripts. statusproc
> currently does something like this, too.
> >     if [ -f "$pidfile" ]; then
> I think this is not quite right. If I asked you to look at
> /var/run/ (as opposed to it just being guessed above), then
> that is exactly what I want to be looking at. If it doesn't exist,
> then it's not running from my perspective. The whole reason I passed
> in the pidfile is so we don't just go blindly searching for any
> process named dbus.
> So, there needs to be two tests: if the variable is set (assuming the
> previous munging is removed), then if it exists.
> if [ -n "$pidfile" ]; then
>     if [ -f "$pidfile" ]; then
> ...

I see your point and it's a good one.  LSB seems to have a different opinion, if I am interpreting the following correctly.  

How often would you specify a non-existent pidfile?  Should this be an error?

How often would you pass a pidfile?  And how many don't reside in /var/run?  I don't know.

(from LSB doc)

The start_daemon, killproc and pidofproc functions shall use the following
 algorithm for determining the status and the process identifiers of the specified

1. If the -p pidfile option is specified, and the named pidfile exists, a single
 line at the start of the pidfile shall be read. If this line contains one or more
 numeric values, separated by spaces, these values shall be used. If the -p
 pidfile option is specified and the named pidfile does not exist, the
 functions shall assume that the daemon is not running.
 2. Otherwise, /var/run/ shall be read in a similar fashion. If this
 contains one or more numeric values on the first line, these values shall be used.
 Optionally, implementations may use unspecified additional methods to locate
 the process identifiers required.
 The method used to determine the status is implementation defined, but should
 allow for non-binary programs.
 Conforming implementations may use other mechanisms besides those based on
 pidfiles, unless the -p pidfile option has been used. Conforming applications
 should not rely on such mechanisms and should always use a pidfile. When a
 System Initialization program is stopped, it should delete its pidfile. Multiple process 
identifiers shall be separated by a single space in the pidfile and in the output of pidofproc.

More information about the lfs-support mailing list