Commit Graph

8 Commits

Author SHA1 Message Date
Matteo Croce
b067ecc886 pidof: allow to suppress output
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
2020-12-22 14:31:17 +11:00
Jan Rybar
bf6c096dbd pidof: new option to show cmdline-less PIDs (kernel workers), empty input fixed 2020-12-22 00:14:41 +00:00
Craig Small
cc032cbd99 docs: some manpage fixes
Some editorial changes so the man pages follow the standards.

References:
 procps#173
2020-06-04 22:25:26 +10:00
Craig Small
c660dbae1b pidof: Fix separator option
Short separator option used 's' instead of 'S' which
meant it pidof would use the single-shot option when you
meant separator.

Added alias for -S using -d to give some sysvinit pidof
compatibility.

References:
    commit 73492b182d
    procps-ng/procps#141
2019-09-21 16:17:05 +10:00
Craig Small
69f4b6ec8e docs: Note limitation of finding scripts in pidof.1
pidof will miss scripts that are run a certain way due to how
they appear in procfs. This is just a note to say it might miss
them.

References:
 procps-ng/procps#17
2018-03-03 18:47:22 +11:00
Masatake YAMATO
73492b182d pidof: allow to change a separator put between pids
I frequency use pidof command with strace system call tracer.
strace can trace MULTIPLE processes specified with "-p $PID"
arguments like:

	  strace -p 1 -p 1030 -p 3043

Sometimes I want to do as following

	  strace -p $(pidof httpd)

However, above command line doesn't work because -p option
is needed for specifying a pid. pidof uses a whitespace as
a separator. For passing the output to strace, the separator
should be replaced with ' -p '.

This maybe not a special to my use case.

This commit introduces -S option that allows a user to specify a
separator the one wants.

    $ ./pidof bash
    ./pidof bash
    24624 18790 12786 11898 11546 10766 7654 5095
    $ ./pidof -S ',' bash
    ./pidof -S ',' bash
    24624,18790,12786,11898,11546,10766,7654,5095
    $ ./pidof -S '-p ' bash
    ./pidof -S '-p ' bash
    24624-p 18790-p 12786-p 11898-p 11546-p 10766-p 7654-p 5095
    $ ./pidof -S ' -p ' bash
    ./pidof -S ' -p ' bash
    24624 -p 18790 -p 12786 -p 11898 -p 11546 -p 10766 -p 7654 -p 5095
    $ strace -p $(./pidof -S ' -p ' bash)
    strace -p $(./pidof -S ' -p ' bash)
    strace: Process 24624 attached
    strace: Process 18790 attached
    strace: Process 12786 attached
    ...

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2018-03-02 21:42:46 +11:00
Jaromir Capik
f5d15f4718 pidof: support for omitted %PPID and additional separators
This commit introduces support for special %PPID value that
can be passed to the -o option as a substitution for parent
PID. It also allows users to use two additional separators
for omitted PIDs - colon and semicolon.
2013-10-14 15:38:33 +02:00
Jaromir Capik
afe862ebe4 pidof: reimplemented from scratch (replacing sysvinit pidof)
As the sysvinit becomes obsolete, some of the bundled tools
need to find a new home. The procps-ng project seems to be
the most suitable project for adopting the pidof tool.
This commit introduces a redesigned version of pidof
that satisfies the LSB requirements.
In corner cases the behaviour might differ from the former
one as the new version doesn't use any stat(2) calls.
2013-10-10 17:01:48 +02:00