Sample Header Ad - 728x90

Why pidof and pgrep are behaving differently?

10 votes
3 answers
11314 views
I have a init script in /etc/init.d/myservice for initialize a service like this: ... start() { ... daemon /usr/sbin/myservice ... } stop() { ... pgrep myservice pidof myservice ps -ef | grep myservice ... } And when I try to stop the service, this is the output: 10000 10001 10000 root 10000 1 0 09:52 ? 00:00:02 /usr/sbin/myservice root 9791 9788 0 10:06 pts/1 00:00:00 /bin/sh /sbin/service myservice stop root 10001 9791 1 10:06 pts/1 00:00:00 /bin/sh /etc/init.d/myservice stop root 9805 9796 0 10:06 pts/1 00:00:00 grep myservice Is this expected? Why pidof is returning only the correct PID of the service that I want to stop and pgrep is returning the service PID and the PID of the init script? Can I rely on that pidof will always ignore the PID from the init script?
Asked by Pigueiras (203 rep)
Feb 27, 2014, 09:14 AM
Last activity: Jun 5, 2016, 02:18 PM