Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeBSD process listing results in "keyword not found" errors #1673

Merged
merged 3 commits into from Jun 28, 2021

Conversation

basil
Copy link
Contributor

@basil basil commented Jun 28, 2021

While testing FreeBSD support in a separate PR, I noticed that some processes weren't getting listed. Debugging it further, I found that ps(1) was printing the following:

$ uname -a
FreeBSD freebsd 13.0-RELEASE FreeBSD 13.0-RELEASE #0 releng/13.0-n244733-ea31abc261f: Fri Apr  9 04:24:09 UTC 2021     root@releng1.nyi.freebsd.org:/usr/obj/usr/src/amd64.amd64/sys/GENERIC  amd64
$ ps -awwxo state,pid,ppid,user,uid,group,gid,nlwp,pri,vsz,rss,etimes,systime,time,comm,majflt,minflt,nvscw,nivscw,args
ps: nvscw: keyword not found
ps: nivscw: keyword not found
STAT  PID PPID USER        UID GROUP       GID NLWP PRI     VSZ   RSS ELAPSED   SYSTIME      TIME COMMAND            MAJFLT MINFLT COMMAND
DLs     0    0 root          0 wheel         0  368 -16       0  5888    2667   0:10.32   0:10.32 kernel                  0      0 [kernel]
[…]
$

Despite the fact that those keywords are listed in the man page, they don't appear to work (at least not on FreeBSD 13.0).

Another problem I noticed was that the list of ps(1) keywords was duplicated in OSHI: once in FreeBsdOperatingSystem and again in FreeBsdOSProcess. The former used 20 arguments, including the broken nvscw and nivscw. The latter used 18 arguments, excluding nvscw and nivscw. Yet both passed the result of the ps(1) invocation to reeBsdOSProcess#updateAttributes(java.lang.String[]), which seemed broken.

I made the two classes consistent with each other by consolidating the list of ps(1) keywords into a single 18-element list that is shared by both classes. The list doesn't contain the problematic keywords. Yes, this means that getContextSwitches() will always return 0, but this seems to have been broken even before this PR, and FreeBSD's getBytesRead() and getBytesWritten() are also broken in this manner today, so I doubt this will be a big problem. And at least this fixes my original problem: now I can get a listing of all processes on the system. I tested this on FreeBSD 13.0 and it resolved my original issue.

@coveralls
Copy link

coveralls commented Jun 28, 2021

Coverage Status

Coverage remained the same at 85.764% when pulling aa1a560 on basil:freebsd into 306445c on oshi:master.

Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's curious how that mismatch didn't get caught until now.

Don't remove the context switches. Just spell the fields right. They end csw (context switch) and not scw (stupid code whoops). :)

Some other suggestions on your changes below.

@dbwiddis
Copy link
Member

Looks great. I'll let CI run and then merge.

@dbwiddis dbwiddis merged commit 3837ac4 into oshi:master Jun 28, 2021
@basil basil deleted the freebsd branch June 28, 2021 23:22
dbwiddis pushed a commit that referenced this pull request Jul 18, 2021
* FreeBSD process listing results in "keyword not found" errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants