This commit makes a task's 'docker' container id (both
full and abbreviated) available within the <pids> API.
It is patterned after that 'lxc' container logic which
tracks ids already seen so as to avoid repeated malloc
plus free calls. It should be noted, however, that the
'docker' ids do not proliferate like those others may.
In implementing the addition, the 'readproc/task' code
had to be tweaked a little. The code for PROC_FILL_LXC
and PROC_FILL_DOCKER now share a buffer containing the
cgroup contents so as to avoid a second file2str call.
[ yes, each container extraction routine may corrupt ]
[ that buffer. and yes, a caller may request both of ]
[ those enums (LXNAME and DOCKER_ID) simultaneously. ]
[ but, a task can be in only one container at a time ]
[ so the buffer would get whacked at most just once. ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch was prompted by the issue referenced below.
Previously the library silently combined the 'D' state
(disk sleep/uninterruptible sleep) with the 'S' state.
That approach meant the reap or select counts were not
at all self documenting. Even worse, since the 'R' and
'D' states were involved in load average calculations,
accurately assessing high load average was impossible.
Now, instead of an arbitrary library decision, callers
can choose to combine or report the counts separately.
[ this change could be made in a way which preserves ]
[ the ABI, requiring bumping this library 'revision' ]
[ only, by placing that new 'disk_sleep' count last. ]
[ that, however, wouldn't be fair to potential users ]
[ of the old 'sleep' value which included 'D' tasks. ]
[ thus, the API is implicitly broken by this change. ]
[ so for clarity, we'll locate 'disk_sleep' adjacent ]
[ to 'sleep' which will then necessitate raising the ]
[ 'current' value then zeroing 'revision' and 'age'. ]
Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/265
Signed-off-by: Jim Warner <james.warner@comcast.net>
Many years ago a truly awful patch was submitted which
purported to add a 'CLS' field to top. That patch, and
a subsequent offering, were rejected. This commit will
allow adding such a field to top and also simplify ps.
We've added this newest field in a way that will break
both our library's API and ABI. As an alternative, the
change could have been implemented as shown in a patch
referenced below. However, a subsequent commit dealing
with <pids> disk_sleep will break both of them anyway.
Reference(s):
https://www.freelists.org/post/procps/PATCH-topadded-scheduling-class-in-top-output,1
Aug, 2016 - expand fields yet maintain API/ABI
commit 09e1886c9e
Signed-off-by: Jim Warner <james.warner@comcast.net>
With the 5.19 kernel two new fields dealing with zswap
were introduced. They are present when CONFIG_ZSWAP is
defined. That configuration seems to be the usual one.
We're adding these new fields in a way that will break
both our library's API and ABI. As an alternative, the
change could have been implemented as shown in a patch
referenced below. However, a subsequent commit dealing
with <pids> disk_sleep will break both of them anyway.
Reference(s):
Aug, 2016 - expand fields yet maintain API/ABI
commit 09e1886c9e
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit just corrects some inconsistencies between
the EU_CPN (cpu number) and EU_NMA (numa node) fields.
Signed-off-by: Jim Warner <james.warner@comcast.net>
. clarify that CGNAME is not available with cgroup v2.
. error_exit() might be called from one signal handler
and it, in turn, calls that bye_bye() function so we
must adjust slightly that latter's prologue comment.
. using 'static' will avoid repeatedly executing the 2
instructions (for initialization) otherwise present.
Signed-off-by: Jim Warner <james.warner@comcast.net>
An addition that's needed for the 'make dist' tarball.
Reference(s):
. Oct, 2023 - units.c was intrduced
commit 460df8aeb5
Signed-off-by: Jim Warner <james.warner@comcast.net>
Strongly inspired from free.c codebase
I had to split PRINT_line into two calls because scale_size reuses the
buffer and that's the easiest workaround for that.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
* Because 's' is synchronous, it's become necessary to indicate when is cmd
running. Without it the user may not be sure whether a 's' will save the
output currently on-screen or the next iteration output. The blank lowheader
is relatively unobtrusive, but might suggest that the timestamp in header is
the time of cmd completion. Also, it puts potentially time-consuming I/O
between cmd iterations. Still, the best option I could think of. Header
semantics is given in manpage.
* Display lowheader when exiting on -e.
* Only refresh() screen when cmd was run this pass through the main loop in
main(). Till now the first line of header was refreshed on-screen each time
the main loop restarted. That was confusing when resizing with -r: current
time in header would update after a resize, suggesting that the cmd was
executed at that time, while it actually wasn't and the cmd output shown
would be invalid: either it'd be old or presented as empty (when clear() used
to be part of the main loop prologue).
Signed-off-by: Craig Small <csmall@dropbear.xyz>
* Removed code that handled STOPped command process. waitpid() doesn't report
those by default.
* Fixed a minor bug in child status processing when WIFEXITED and WEXITSTATUS=0
(topic branch regression).
* Moved two TODOs to gitlab issues.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
* Included cmd exitcode in 2nd line of header.
* Reverted back to "in" from "ran" in running time display. Looks better.
* Manpage: moved info on header from -t description to intro.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
* -e exits with cmd's last exit code. Possibly a regression fix, similar
function used to be mentioned in manpage.
* Without -e, exit codes partitioned into success (0), cmd-related errors (2),
other errors (1).
* Child returns sh-like codes on signal and failure to exec/wait.
* Replaced xerr()s following ncurses init with a ncurses-aware exit.
* Removed unnecessary clear() when screen resizes.
* Replaced the ambiguous "in" with "ran" in lowheader.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
* Removed the intro comment: it's >20 years old, some things clearly no longer
hold (UNUSED, the bug in glibc, Linux ports, ...). Replaced it with some
boilerplate intro.
* Updated manual defines of missing macros (explained in comments). Removed the
EMT/STKFLT situation (ancient).
* All functions now account for SIGRTMAX.
* Placed all known non-RT signals into sigtable[]. There's no need anymore to
try hard to only keep uniquely-numbered signals in it and to make them a
complete sequence. Most kinds of updates to the signals can be accomplished
just by editing the table. All functions accomodate, there's no longer a need
for them to maintain exceptions (most of them).
* No function returns a freeable pointer.
* strtosig(): Re-write (old one didn't handle synonyms, interpreted malloc()
failure as signal not found).
* On the auxiliary, implemented a stable sort. The stability of qsort() is
unspecified.
References:
!207
* When cmd took longer than -n to complete, -p is no longer skipping sleeps to
make up for the time lost waiting for the completion(s) [BUG].
* Code cleanup, minor optimization. Moved universal routines to
strutils/fileutils.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
* -d considers all columns the new char will occupy, not just the first one.
When 日a -> a日a, 日 is now highlighted (because of the change in its 2nd
column).
Signed-off-by: Craig Small <csmall@dropbear.xyz>
* Worked around a ncurses bug of applying combining characters to the base
character preceding the target one. -d now operates on all components of
complex characters. Removes a BUG.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
* Manpage:
* Reduced EXIT STATUS to 0 and other. The others were uninteresting in a
manpage and passing cmd exitcode doesn't work.
* Removed BUG about combining characters in last column. AFAICS it's gone.
* Removed BUG about -p not killing cmd when it takes too long. That can be a
new feature, but the current behavior is what a lot of people might well
expect by default.
* Re-phrased the BUG with "rapid-fire" in it. Makes it look like a fork bomb.
* Impl. mbswidth(), the strlen()/wcswidth() for multi-byte strings.
* In header printing:
* Fixed a few bugs in positioning and truncation (it's ctime()).
* For 8BIT, column widths are considered instead of mbstring lengths (not just
for the cmd).
* ENOMEM handled after asprintf().
* ctime() -> strftime() for a localized string. Left out date. Ok?
* Most of header is pre-composed for speed.
* -qN, N < 1, becomes -q1.
* When screen resizes, -q now only pauses for a turn, doesn't restart. This is
probably as much as can be done without a modification to the change-detecting
routine.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
* Manpage:
* Rewrote the description of -p. It wasn't saying what -p did.
* Added COLUMNS and LINES to ENVIRONMENT.
* Refreshed EXAMPLES, moved it up to be before BUGS.
* Regression in topic branch: tabs now print properly.
* Removed output into the hijacked stdout/err following fork().
* EINTR-protected watpid()s and the release of fds to prevent leaks.
* Removed the measure taken in Debian#240989 to circumvent faulty is(w)print().
Glibc has been fixed (verified) and as it was, watch was letting all non-ASCII
non-printables into output. I'm not terribly certain about this one, but I
figure people with old glibc also have old procps.
* Ensured reading cmd output is buffered. We do a lot of getc() from it.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
* Moved character printing out of run_command() and into a new function to clean
run_command() up and isolate self-contained functionality.
* Main loops in run_command() simplified greatly.
* Bugs fixed:
* -g and -q now coexist well (both apply). Formerly, "watch -g -q X" with cmd
output changing would act as "watch -q X" with cmd output not changing.
* -d highlight no longer removes color.
* -c together with -d no longer mark the entire screen as ever-changing.
* malloc() of "wcommand" in main() corrrected (sizeof(item_ptr) ->
sizeof(*item_ptr)). Also present in a commit in another merge request, but
I could no longer keep scrolling over it.
* -q counter now restarts when terminal size changes. That puts it in sync
with the lifecycle of first_screen and prevents the counter from progressing
extra fast due to the frequent restarts of the command during the resizing.
* Regression within topic branch: -g is no longer ignored.
* Larger blank areas are now drawn using dedicated ncurses routines, resulting,
I presume, in faster & cheaper operation. Not confirmed.
* Manpage:
* Changed the -x option description. The old one made it seem like it's the
same thing, only better and everyone wants it, disregarding the fact that
it behaves differently and that this difference is probably more important
than the convenience regarding quoting.
* fgrep is obsolete, in GNU grep at least.
* Made the BUG "Non-printing characters..." into a NOTE. Some common
non-printables are actually accounted for and the others would probably ruin
the day of half the people.
* Reduced the BUG "Upon terminal resize..." The screen does get repainted when
its dimensions change. The -r is intended to prevent the screen from
repainting.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
* Avoid re-computing strlen(command) every time header is printed.
* Regression within topic branch: diff once again accounts for blank space.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
* Fixed bug from watch(1): "Blank lines directly after a line which ends in the
last column do not display."
* Cursor is now hidden.
* Bug from watch(1) involving missing compound characters may have been fixed as
well. I can see no issues with canonically decomposed characters in UTF-8, if
that's what it's regarding. The BUGS stays, however, until this is confirmed.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
Errors fixed when --no-wrap:
* empty line following a truncated line omitted from output
* overlong line isn't truncated when the truncation should happen "in the
middle" of a wide (wcwidth) wchar
Signed-off-by: Craig Small <csmall@dropbear.xyz>
Minor optimisations (narrower types)
Fixed indentation
minor fixes (wcwidth() only if not WEOF, wint_t accessed as *(wchar_t *)&var)
Signed-off-by: Craig Small <csmall@dropbear.xyz>