On Mon, Sep 11, 2023 at 5:29 AM Marc Espie <marc.espie.open...@gmail.com>
wrote:

> On Mon, Sep 11, 2023 at 12:10:17PM +0200, Claudio Jeker wrote:
> > On Mon, Sep 11, 2023 at 11:02:00AM +0200, Marc Espie wrote:
> > > I was reading through ps.1, which has two slightly different options
> > >      -H      Also display information about kernel visible threads.
> > >      -k      Also display information about kernel threads.
> > >
> > > It's not at all obvious what the difference between these options
> might be.
> >
> > kernel threads == kthread(9) created threads
> >
> > Those should have K in STAT and the name is in () like:
> >  3141 ??  RK/1   4057:57.90 (idle1)
>

Fun fact: at the current time, all kernel threads are actually full
processes, though this just wastes some memory and cache.
Part of my (evil) plan in adding thread names was removing an impediment in
changing kthread_create(9) to create just a thread inside process 0.


> kernel visible threads == __tfork_thread(3) created threads for userland
> > applications. For example:
> >
> > 43838  556612 ??  IpU      0:01.58 firefox (firefox/Cache2 I/O)
> > 43838  415551 ??  IpU      0:00.01 firefox (firefox/Cookie)
> > 43838  377915 ??  IpU      0:00.01 firefox (firefox/Worker Launcher)
> >
> > These threads all share the same PID but have different TID.
> >
> > I think the "kernel visible" is there to tell that pure userland threads
> > can not be reported by ps. I think go routines are such an example.
>

Claudio's descriptions are correct.  How to massage those into the ps(1)
manpage is unclear to me.



> Any of you guys willing to provide a patch to ps(1) and kvm_getprocs(3) ?
>

I think I've written a diff for kvm_getprocs(3) at least 3 times and each
previous time the way the API makes me grit my teeth has resulted in
incomplete rewrites of the API and its callers that I haven't been happy
enough with to complete and push through.  Enough stalling on documenting
the current behavior: how about something like the diff below?

Philip

 Index: lib/libkvm/kvm_getprocs.3
===================================================================
RCS file: /data/src/openbsd/src/lib/libkvm/kvm_getprocs.3,v
retrieving revision 1.21
diff -u -p -r1.21 kvm_getprocs.3
--- lib/libkvm/kvm_getprocs.3   11 Aug 2019 15:48:08 -0000      1.21
+++ lib/libkvm/kvm_getprocs.3   12 Sep 2023 04:25:32 -0000
@@ -91,6 +91,13 @@ processes with real user ID
 .Fa arg
 .El
 .Pp
+In addition, if
+.Dv KERN_PROC_SHOW_THREADS
+is bitwise ORed into
+.Fa op
+then additional entries for matched processes' associated threads
+are returned.
+.Pp
 Only the first
 .Fa elemsize
 bytes of each array entry are returned.

Reply via email to