Bug 201317 - pidof matches symlinks
pidof matches symlinks
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: SysVinit (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Bill Nottingham
David Lawrence
Depends On:
  Show dependency treegraph
Reported: 2006-08-04 06:59 EDT by Ingvar Hagelund
Modified: 2014-03-16 23:01 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2008-12-08 15:13:33 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Ingvar Hagelund 2006-08-04 06:59:16 EDT
Description of problem:
pidof matches symlinks. Should not be so, or at least should be documented.

Version-Release number of selected component (if applicable):
2.85-34.3 (but probably others as well)

How reproducible:

Steps to Reproduce (or the way we found out):

1. Set up a local version of a system service like httpd, say
/usr/local/sbin/httpd81, a symlink to /usr/sbin/httpd, with it's own
/etc/httpd81, /etc/sysconfig/httpd81, /etc/init.d/httpd81, cloned and adjusted
from the system scripts

2. Start (system) httpd, start (local) httpd81 with the service command

3. Stop the (local) httpd81 with the service command.
Actual results:
All httpd, including the system's standard httpd, processes dies. Sad sysadmin.

Expected results:
Only the local service should die

Additional info:
This is caused by pidof, as the system script uses the function killproc, which
in turn uses pidof to localize pids when the pidfile is nonexisting or empty

# pgrep httpd81 | wc
      0       0       0
# pgrep httpd | wc
     31      31     186
# pidof /usr/local/sbin/httpd81 | wc # This is imho clearly wrong
      1      31     186

This seems to be because pidof follows symlinks. If this is a "feature", I think
it should be noted in the manpage.

Also note that pidof operates the (my) expected way if running as a non-root
user. Beats me why.

Copying or hardlinking the binary instead of symlinking resolves the problem.
Comment 1 Bill Nottingham 2008-12-08 15:13:33 EST
Apologies for the extreme delay in handling this. Given that the executable for running processes is determined by readlink() of /proc/$PID/exe, this behavior is expected and unavoidable.

I'm doucmenting this behavior in the manage page in our development version; furthermore, the current Fedora release (F10) checks pid files before pidof when stopping programs, so the problem should be fixable on that end for any services started in this way.

Closing as WONTFIX for RHEL 4; the man page change will go into RHEL 6.

Note You need to log in before you can comment on or make changes to this bug.