Skip to content

pidof: allow to suppress output

Matteo Croce requested to merge teknoraver/procps:master into master

Often pidof is used in shell scripts in this form:

if pidof daemon >/dev/null; then
    ...
fi

The redirection to /dev/null is needed because otherwise the script would output the found PIDs. Let's add a -q option which, similary to grep, just sets the exit code. Also exit on first match, as there is no reason to proceed further when at least a process is matched.

Tested with:

$ ./pidof bash
17701 14019 5276 2967
$ echo $?
0
$ ./pidof bashx
$ echo $?
1
$ ./pidof -q bash
$ echo $?
0
$ ./pidof -q bashx
$ echo $?
1

Merge request reports