Commit Graph

388 Commits

Author SHA1 Message Date
Paul Slootman
104b3ce3df Library: Recover from meminfo seek() in LXC
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>
2024-06-23 17:28:21 +10:00
Craig Small
734930e476 library,w: Only show and count user sessions
Previously all sessions were used
library - procps_users counted sessions, not user sessions
w - showed all sessions, not user sessions

$ loginctl list-sessions
SESSION  UID USER   SEAT  LEADER CLASS         TTY  IDLE SINCE
     10    0 root   -     17860  manager-early -    no   -
     12 1000 csmall seat0 19370  user          tty5 no   -
      5 1000 csmall seat0 4629   user          tty4 no   -
      6 1000 csmall -     4644   manager       -    no   -
      9    0 root   seat0 3633   user-early    tty2 no   -
$ loginctl list-sessions
SESSION  UID USER   SEAT  LEADER CLASS         TTY  IDLE SINCE
     10    0 root   -     17860  manager-early -    no   -
     12 1000 csmall seat0 19370  user          tty5 no   -
      5 1000 csmall seat0 4629   user          tty4 no   -
      6 1000 csmall -     4644   manager       -    no   -
      9    0 root   seat0 3633   user-early    tty2 no   -

5 sessions listed.
$ loginctl list-users
 UID USER   LINGER STATE
   0 root   no     online
1000 csmall no     active

2 users listed.

Old w:
$ src/w
 21:34:32 up 49 min,  5 users,  load average: 0.25, 0.22, 0.22
USER     TTY       LOGIN@   IDLE   JCPU   PCPU  WHAT
csmall             20:45    9:34   0.00s  0.23s /usr/lib/systemd/systemd --user
root               21:24    9:34   0.00s  0.11s /usr/lib/systemd/systemd --user
csmall   tty5      21:26    8:22   0.04s  0.01s -bash
root     tty2      21:24    8:48   0.05s  0.02s -bash
csmall   tty4      20:45   49:32   0.03s  0.02s /usr/libexec/gnome-session-binary

New w:
$ src/w
 21:33:23 up 48 min,  3 users,  load average: 0.07, 0.22, 0.22
USER     TTY       LOGIN@   IDLE   JCPU   PCPU  WHAT
csmall   tty5      21:26    7:13   0.04s  0.01s -bash
root     tty2      21:24    7:39   0.05s  0.02s -bash
csmall   tty4      20:45   48:23   0.03s  0.02s /usr/libexec/gnome-session-binary

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2024-06-04 21:34:58 +10:00
Jim Warner
54e1220756 NEWS: cite the new open file descriptors in <pids> api
Signed-off-by: Jim Warner <james.warner@comcast.net>
2024-05-12 18:09:17 +10:00
Craig Small
be02d8af31 ps: Another go at AIX formats
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>
2024-05-10 20:24:09 +10:00
Jim Warner
f214982045 NEWS: mention loss of 'info' parameter in 'VAL' macros
Signed-off-by: Jim Warner <james.warner@comcast.net>
2024-04-28 15:25:31 +10:00
Jim Warner
fe61b17303 NEWS: mention top color, meminfo and stat enhancements
Signed-off-by: Jim Warner <james.warner@comcast.net>
2024-03-21 14:24:13 +11:00
Craig Small
d5946ef5f1 uptime: Add container uptime option
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>
2024-02-08 16:47:21 +11:00
Craig Small
1c004ece03 library: Add procps_uptime_snprint
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>
2024-02-07 18:07:34 +11:00
Craig Small
07fb8d86e0 pgrep: rework pidfile to be able to use stdin
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>
2024-02-06 21:10:46 +11:00
zhenwei pi
460f0b4010 hugetop: Introduce utility to display system/process huge page information 2024-01-31 06:34:33 +00:00
Craig Small
5773a51331 library: Promote procps_users to external function
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>
2024-01-31 17:17:09 +11:00
Craig Small
bf013807d6 ps: Add huge table fields
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>
2024-01-30 20:12:41 +11:00
Jim Warner
a1ab8539be NEWS: update for the 'docker' containers in <pids> api
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Jim Warner
0ffd98f652 NEWS: acknowledged separate 'disk sleep' in <pids> api
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Jim Warner
c9b3a2ddbc NEWS: mention change to 'SCHED_CLASSSTR' in <pids> api
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Jim Warner
d5f74ee3bc NEWS: updated with new 'ZSWAP' fields in <meminfo> api
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Craig Small
f9927c6650 docs: Add manpage and NEWS for human slabtop
Update slabtop.1 to describe --human flag
Added NEWS entry

References:
 https://www.freelists.org/post/procps/Add-human-flag-to-slabtop
 commit c4f33bc302
2023-10-11 18:01:22 +11:00
Jim Warner
92bdeb176f NEWS: acknowledge fix for the lost tasks ps issue #304
[ 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>
2023-10-05 07:28:32 +11:00
Craig Small
23491ebf40 pgrep: Add match to environment variable
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>
2023-10-04 21:55:06 +11:00
Craig Small
3431c17d45 ps: Add environment output
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>
2023-10-04 20:53:30 +11:00
Craig Small
0892f0b823 watch: Use clock_gettime where available
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>
2023-10-04 20:32:43 +11:00
Craig Small
d59797b4cd misc: Add NEWS for previous glob commit
Added NEWS entry for sysctl glob exclude

References:
 commit 39748b78b0
 !206

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-04 19:54:55 +11:00
Craig Small
1c61ac2c61 w: Cache pids and other enhancements
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>
2023-10-04 16:35:21 +11:00
Robert Malz
bfb0eadc38 uptime: fix output on 60 seconds
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>
2023-09-21 16:45:49 +10:00
Craig Small
91ff8d9959 library: days/users when value is 0
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
2023-09-21 16:32:34 +10:00
Craig Small
79042e07fa ps: Don't crash when using short option
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>
2023-09-12 16:59:18 +10:00
Craig Small
ca004d4657 build-sys: Add systemd/elogind to w
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>
2023-08-31 22:24:23 +10:00
Craig Small
4ddcef2fd8 NEWS: This is Version 4.0.4
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-31 19:54:51 +10:00
Craig Small
469b964621 library: Increment revision
There have been some internal updates, library is now 0:2:0

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-19 17:47:08 +10:00
Craig Small
0632609efd misc: Add NEWS for escape fix
References:
 49f92f690c
 https://bugs.debian.org/1035649
2023-08-19 17:26:04 +10:00
Craig Small
c10ba96147 ps: Add --signames to print signal names
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:
 !98
 https://gitlab.com/mcgrof/sigstat

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-16 17:00:31 +10:00
Craig Small
11c91313c9 watch: Add compile time flag to support color
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>
2023-08-15 21:26:13 +10:00
Craig Small
0f4de1c438 misc: Add NEWS for pidof -t
Added NEWS item for previous commit to add -t option to pidof

References:
 dd9310da0b19c06382ee205f77ed211dd8ba8ccf
 !190
2023-08-15 21:04:06 +10:00
Craig Small
a7a03ba4e4 pmap: Reset totals between procs with -X or -XX
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>
2023-08-15 20:52:14 +10:00
Craig Small
2c933ecba3 ps: Fix possible buffer overflow in -C option
ps allocates memory using malloc(length of arg * len of struct).
In certain strange circumstances, the arg length could be very large
and the multiplecation will overflow, allocating a small amount of
memory.

Subsequent strncpy() will then write into unallocated memory.
The fix is to use calloc. It's slower but this is a one-time
allocation. Other malloc(x * y) calls have also been replaced
by calloc(x, y)

References:
 https://www.freelists.org/post/procps/ps-buffer-overflow-CVE-20234016
 https://nvd.nist.gov/vuln/detail/CVE-2023-4016
 https://gitlab.com/procps-ng/procps/-/issues/297
 https://bugs.debian.org/1042887

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-10 21:22:23 +10:00
Craig Small
7a46278fce misc: Add NEWS for last two commits
References:
 merges #197 #198

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-07-30 21:37:19 +10:00
Craig Small
9fc76f7feb misc: Add NEWS for previous
References:
 commit 2eafd0a215
 !193

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-07-13 20:27:48 +10:00
Craig Small
f4eeff0b26 vmstat: Print guest time
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>
2023-07-11 19:16:15 +10:00
Craig Small
cfb3c482a5 pgrep: Suppress warning if using regex
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>
2023-06-13 16:23:35 +10:00
Jim Warner
bc688d630a library: restore the proper main thread tics valuation
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>
2023-05-31 18:25:07 +10:00
Jim Warner
dd6a99c92d NEWS: include several more changes since release 4.0.3
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-05-31 17:49:08 +10:00
Craig Small
c8afe6ff84 w: Fix musl UT_HOSTSIZE issue
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>
2023-05-07 20:27:50 +10:00
Craig Small
b31ac2dcce free: Show single line statistics
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>
2023-05-02 20:32:38 +10:00
Jim Warner
0e98e06777 NEWS: darn, I forgot to label one change as issue #272
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-04-05 07:20:35 +10:00
Jim Warner
c2ab0adc6d NEWS: include several more changes since release 4.0.3
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-03-26 21:08:33 +11:00
Craig Small
8c81808de0 pgrep: Use only --signal option for signal
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
2023-03-01 17:35:14 +11:00
Craig Small
9b2f49166b tests: Dont compare floats with ==
Comparing floats with == is bad and I should feel bad I did this.
The problem is if something is close to, but not quite the exact
same fails tests.

I have used an epsilon of 1 because we don't care about accuracy,
just that the function works well enough.

References:
 issue procps-ng/procps#271
 https://how-to.fandom.com/wiki/Howto_compare_floating_point_numbers_in_the_C_programming_language

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-03-01 17:20:42 +11:00
Craig Small
806eb270f2 NEWS: Release 4.0.3 2023-02-16 07:26:15 +11:00
Jason Cox
848be2b1e2 pgrep: make --terminal respect other criteria
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>
2023-01-25 20:34:21 +11:00
Qin Fandong
0a5ccbdd42 vmstat: precision issues in unitConvert()
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
2023-01-18 17:02:53 +11:00