Running procps tools under LXC may fail with the message:
"Unable to create meminfo structure"
This is due to a lseek() failing with a ESPIPE error.
It doesn't appear to impact all LXC installations and it's
unclear why some are impacted and some not.
The fix is to check for that error and reopen the file
if required.
References:
https://bugs.debian.org/1072831
Signed-off-by: Craig Small <csmall@dropbear.xyz>
Previous commits around AIX formats fixed some issues but meant that some
of the useful features of that format were missing.
The problem is that AIX uses %* and standard formats use %* too for
%cpu and %mem.
The trick is to use AIX parser when there is a % but not when its
for the "normal" fields.
%mem is easy as there is no %m AIX equivalent so "%m*" means
don't use AIX parser.
%cpu is harder. "%cpu" "%cpu pid" or "%cpu,pid" are to be
parsed normally, but "%cpuXpid" is AIX "%c Xpid".
I think I've caught all the odd cases, but I'm sure there is some
strange combination I have missed.
References:
#323
commit 8cb646bdfc
Signed-off-by: Craig Small <csmall@dropbear.xyz>
Either -c or --container or environment PROCPS_CONTAINER
will show the container, as opposed to the systems
uptime.
References:
#300
commit 989fa41d4f
Signed-off-by: Craig Small <csmall@dropbear.xyz>
Uses the same format as the current procps_uptime_sprint*
functions.
Uptime is given, not assumed. This is so if, for example,
container uptime is given then the function will work.
Non-pretty format uses same logic as pretty format for
days and hours to be consistent.
Uses a given string buffer like snprintf() instead of a
static internal buffer.
Partly solves container uptime issue #300
Signed-off-by: Craig Small <csmall@dropbear.xyz>
moved opt_pidfile and opt_lock out of global
changed open to fopen
removed restriction to pidfile so you can use stdin
References:
issue #318
Signed-off-by: Craig Small <csmall@dropbear.xyz>
The user count is useful for not expanding the uptime_sprintf
functions. This way there is a standard method of getting the
uptime, user count and load average.
This will be used in the next commit for the uptime program
as a start.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
Added format fields htprv and htshr to ps for Huge Table
allocations private and shared respectively.
Added test for htprv field. Testing shared is possible but more
complex due to the requirement of it being shared across
processes.
Inspired by the discussion around hugetop.
References:
https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt!214
Signed-off-by: Craig Small <csmall@dropbear.xyz>
[ and eliminate 1 decades old useless initialization ]
Reference(s):
. Sep, 2023 - fix for ps issue #304
commit 09fbd70de3
Signed-off-by: Jim Warner <james.warner@comcast.net>
prep --env=KEY=value
Matches processes that have the environment variable KEY set to
VALUE
References:
#167
Signed-off-by: Craig Small <csmall@dropbear.xyz>
Added environment output for ps, using
ps -o environ
Default length is 31 characters, like for the other "long" fields.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
clock_gettime(CLOCK_MONOTONIC) is not impacted by the admin changing the
time and is always equal or more than the previous call (e.g. time never
goes backwards).
References:
#295
Signed-off-by: Craig Small <csmall@dropbear.xyz>
Load and cache the pids list once like previous version of w as
re-scanning each user is time consuming.
Make sure utmpx structure is sent when not using systemd, stops
a segfault due to empty host value
Re-worked main loops as we either had branches (systemd) or two loops
(other) when just checking for username was all that was needed.
References:
#305
Signed-off-by: Craig Small <csmall@dropbear.xyz>
When procps_uptime will return 60 seconds uptime -p will not
provide any output except "up". To stay consistent with other
time units the expected output is "up 0 minutes".
References:
#302
Signed-off-by: Craig Small <csmall@dropbear.xyz>
The check for using days/users was > 0 which meant you could
get results like 0 day or 0 user. The check is now for not 1
so w prints 0 days and 0 users.
References:
#303
ps would crash with the -si or -sf options with systemd enabled.
The issue was the utmp wasn't filled in, the long option checked, the
short option did not.
Refactored the showinfo() function so instead of a branch with duplicate
prints for the items in both long and short we just branch on the items
for long output.
Also, made the function prototypes not dependendent on systemd enabled,
it was too messy that way and passing a char* NULL is not really going
to hurt anything.
References:
#301
Signed-off-by: Craig Small <csmall@dropbear.xyz>
Depending on the compiler flags, w needs to be explictly linked
to libsystemd or elogind even though libproc2 is linked to it.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
Fields such as pending, blocked, ignored and caught would only show
an incomprehensible hexadecimal field for signals, with the
--signames option it now shows the short name.
Largely based on the work of @mcgrof
References:
!98https://gitlab.com/mcgrof/sigstat
Signed-off-by: Craig Small <csmall@dropbear.xyz>
configure --enable-colorwatch will make watch run as if
the --color option is always on. Add the -C,--no-color
option to remove color.
References:
#296
Signed-off-by: Craig Small <csmall@dropbear.xyz>
When pmap used with -X or -XX option with multiple pids, the
totals were not reset between the pids, meaning the first total
was for pid1, but second total was for pid1+pid2.
These running totals are now reset when they are printed, meaning
each total is for it's own pid only.
References:
issue #298
Signed-off-by: Craig Small <csmall@dropbear.xyz>
Guest time was removed from User time but not printed. This meant
that if guest time was non-zero then the CPU numbers did not add
up to 100%
References:
!191!113
commit 2461bb5bc1
Signed-off-by: Craig Small <csmall@dropbear.xyz>
pgrep gives a warning if the match string is longer than
15 characters and there was no match. That often does not
make sense when using regex or at the very least difficult
to know when to warn users. e.g
"1234567890|123456789X" is a 21 character string but only
matching two 10 string words.
pgrep has a simple check for regex and will now suppress
that warning if that has been used.
References:
https://bugs.debian.org/1037450
Signed-off-by: Craig Small <csmall@dropbear.xyz>
The issue cited below revealed an earlier commit, also
shown below, resulted in an incorrect tics value for a
thread group leader. That change was made so the group
leader would have a proper autogroup id, not a -1 that
was shown with sibling threads which lacked that file.
So this patch will just restore pre version 4 behavior
while not upsetting LIBPROC_HIDE_KERNEL functionality.
[ this change means that when THREAD mode is active, ]
[ the autogroup id & nice values won't be available. ]
[ they were only shown for the group leaders anyway. ]
Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/280
. Aug, 2021 - thread group leader change
commit a375262609
Signed-off-by: Jim Warner <james.warner@comcast.net>
While musl has utmpx.h, their header file does not define all the
values, especially __UT_HOSTSIZE and friends. Instead it just
hard codes the sizes :/
This change will look for that definition specifically and if
not found will include utmp.h too. Checked on Alpine 3.17
musl just makes these a stub so w doesn't work anyway.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
Added the -L --line option to free to show a small
set of memory statistics on a single line of 80 characters.
Largely based on the work of @Ulenrich1 and updated to
the new API.
References:
procps-ng/procps#156
Signed-off-by: Craig Small <csmall@dropbear.xyz>
When pgrep was used to match on signal, it makes sense to use
the same signal parsing code as pkill. Unfortunately the
"find the signal" part is a little too enthusaistic about what a
signal is, meaning
pgrep -u -42
fails because the signal becomes "42" and then there is no UID.
This is a bit sad for pkill but has been that way for a long
time. For pgrep this is new so now only the long form
pgrep --signal <X>
will work.
In addition, when using --signal if pgrep/pkill couldn't work
out what the signal was it just silently ignored it. It now
complains and aborts.
References:
https://bugs.debian.org/1031765
commit 866abacf88
In some cases the --terminal option to pgrep will cause all processes
matching the terminal to be output, even if other criteria would exclude them.
Specifically, I noticed that it overrides the --runstates option.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
Fix conversion errors due to precision issues in function unitConvert
For example: unitConvert(98720620) will return 98720624, not 98720620.
Because we do (unsigned long)(float)98720620 in function unitConvert
and this is wrong! We should do (unsigned long)(double)98720620 here.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
References:
procps-ng/procps!75