There was a time when that procps.h file served a more
traditional role. Prior to the commit referenced below
it held just macros plus manifest constants. But, with
that change, such items were replaced with a series of
includes embracing all the library exported functions.
That approach was known to disguise errors which would
have otherwise yielded a compiler warning. And without
such a warning, there was no way to address the error.
So this patch will trade the all inclusive header file
approach for individual includes only where necessary.
Reference(s):
. April 2016, procps.h header file revamped
commit ccb6ae8de1
. Sept 2018, top abandoned use of procps.h
commit a6dfc2382e
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit just address the two warnings shown below.
Reference(s):
pgrep.c: In function `select_procs':
pgrep.c:535:12: warning: variable `now' set but not used [-Wunused-but-set-variable]
535 | time_t now;
| ^~~
pidof.c: In function `select_procs':
pidof.c:201:9: warning: `stat_cmd' may be used uninitialized in this function [-Wmaybe-uninitialized]
201 | !strcmp(program, stat_cmd) ||
| ^~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Jim Warner <james.warner@comcast.net>
Reimplementation of pidof for procps toolset contains sort of deactivated code and does not return results for processes without task.cmdline entry (usually kernel worker threads). Old pidof and pgrep do that in comparison. Despite all perks provided by using pgrep instead, pidof should show those workers again.
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 73492b182dprocps-ng/procps#141
Note: unlike "size" and "omit_size", "path_alloc_size" is not multiplied
by "sizeof(struct el)" but the checks in grow_size() allow for a roughly
100MB path_alloc_size, which should be more than enough for readlink().
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>
Since the VAL macro now requires a 4th parameter, this
commit simply adds the 'info' context structure to it.
In some cases, that context structure needed to become
global, since it was referenced in multiple functions.
Signed-off-by: Jim Warner <james.warner@comcast.net>
With this patch we've completed a progression toward a
standard approach to naming conventions which follows:
* Only functions will begin with that 'procps_' prefix
. ........................................... examples
. procps_vmstat_get ()
. procps_diskstats_select ()
- ----------------------------------------------------
* Exposed structures begin with the module/header name
. ........................................... examples
. struct pids_info
. struct stat_reaped
- ----------------------------------------------------
* Item enumerators begin like structs, but capitalized
. ........................................... examples
. VMSTAT_COMPACT_FAIL
. MEMINFO_DELTA_ACTIVE
[ slabinfo varies slightly due to some item variants ]
. SLABINFO_extra
. SLABS_SIZE_ACTIVE
. SLABNODE_OBJS_PER_SLAB
[ could cure with a prefix of SLABINFO, but too long ]
- ----------------------------------------------------
* Other enumerators work exactly like item enumerators
. ........................................... examples
. PIDS_SORT_ASCEND
. STAT_REAP_CPUS_AND_NODES
- ----------------------------------------------------
* Macros and constants begin just like the enumerators
. ........................................... examples
. #define SLABINFO_GET
. #define DISKSTATS_TYPE_DISK
- ----------------------------------------------------
Signed-off-by: Jim Warner <james.warner@comcast.net>
I've got nothing to add to the commit message but that
doesn't mean I won't produce perfectly justified text.
Signed-off-by: Jim Warner <james.warner@comcast.net>
A difference in behaviour between the sysvinit and procps pidof
was that the procps one would sometimes not find process that
the sysvinit one did.
The difference is that if a space is found in argv[0] then sysvinit
would look at cmd for a match. This isn't perfect and more of a
best guess but does often work.
procps pidof now follows the same "standard". The most obvious
difference is with kde based processes and incoming ssh connections
with sshd.
References:
Commit 3f5b75035e
GitLab issue #4https://gitlab.com/procps-ng/procps/issues/4https://github.com/limingth/sysvinit/blob/master/sysvinit-2.88dsf/src/killall5.c#L800
The includes used to define a lot of things a library include
should not. It was also a bit messy what was exposed in the library
and what was not.
get_pid_digits -> procps_pid_length and exported correctly
MALLOC attribute move into relevant .c files
NORETURN attribute moved to relevant .c, not used in library
PURE attribute removed, it wasn't used
KLONG/KLF/STRTOUKL were fixed for long, so now just use long
HIDDEN attribute removed. It was for 3 functions. The PROCPS_EXPORT
seems to do the same (opposite) thing.
likely/unlikely removed from most places, its highly debateable
this does anything useful as CPUs have gotten smarter about branches.
Re-arranged the includes, ALL external programs should just #include
<proc/procps.h> then proc/procps.h includes headers for files that
have exported functions. procps.h and the headers it includes should
not use items that are not exportable (e.g. hidden functions or
macros) they go in procps-private.h
As an additional test of the viability of the new pids
API, the pidof program has now been converted. As part
of that effort, several library changes were prompted:
. individual reads were added as an alternative to the
all encompassing (maybe over broad?) 'reap' provision.
. an alternate version of cgroup, cmdline plus environ
has been added to represent actual vectorized strings.
Signed-off-by: Jim Warner <james.warner@comcast.net>
The function pid_link tries to handle programs which contain very
long paths to their executables. If 1024 bytes are not enough to
contain the path, the loop wants to get more and more space until
the path can fit.
The loop's condition does not fit though.
readlink will never return a value higher than its supplied size
limit, which is "path_alloc_size - 1", therefore the loop-check of
"len == path_alloc_size" will always be false: the loop will never
be repeated.
While at it, the if-condition inside the loop's body can be omitted,
because it is always true.
Benno Schulenberg suggested some changes to the help messages
to provide some consistency and clarity for both the users and
translators of procps.
The test needed to be updated as the pmap output changed too.
Signed-off-by: Craig Small <csmall@enc.com.au>
To assist translators, the help lines are split so that each translation
chunk has one option. This gives bonus of if we add or change an option,
only that option remains untranslated rather than the entire help block.
Reference:
http://www.freelists.org/post/procps/procpsng-for-Translation-Project,1
Signed-off-by: Craig Small <csmall@enc.com.au>
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.
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.