fs/proc: add Kthread flag to /proc/$pid/status
Subsystems (3)
PATCH 1/1 fs/proc: add Kthread flag to /proc/$pid/status
The command ps -ef and top -c mark kernel thread by '[' and ']', but sometimes the result is not correct.
The task->flags in /proc/$pid/stat is good, but we need remember the value of PF_KTHREAD is 0x00200000 and convert dec to hex. If we have no binary program and shell script which read /proc/$pid/stat, we can know it directly bycat /proc/$pid/status.
--- Documentation/filesystems/proc.rst | 2 ++ fs/proc/array.c | 7 +++++++ 2 files changed, 9 insertions(+)
Documentation/filesystems/proc.rst +2 -0
@@ -179,6 +179,7 @@ read the file /proc/PID/status:: Gid: 100 100 100 100 FDSize: 256 Groups: 100 14 16 + Kthread: 0 VmPeak: 5004 kB VmSize: 5004 kB VmLck: 0 kB
@@ -256,6 +257,7 @@ It's slow but very precise. NSpid descendant namespace process ID hierarchy NSpgid descendant namespace process group ID hierarchy NSsid descendant namespace session ID hierarchy + Kthread kernel thread flag, 1 is yes, 0 is no VmPeak peak virtual memory size VmSize total program size VmLck locked memory size
fs/proc/array.c +7 -0
@@ -434,6 +434,13 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,task_state (m, ns, pid, task); +seq_puts (m,"Kthread:\t" ); +if (task->flags &PF_KTHREAD ) { +seq_puts (m,"1\n" ); + }else { +seq_puts (m,"0\n" ); + } +if (mm) {task_mem (m, mm);task_core_dumping (m, task);
Signature · 1 line
2.39.1
Randy Dunlap
reviewerHi,
Quoted 27 lines · Chunguang Wu
The command
ps -efandtop -cmark kernel thread by '[' and ']', but sometimes the result is not correct.
Thetask->flagsin/proc/$pid/statis good, but we need remember the value ofPF_KTHREADis0x00200000and convert dec to hex. If we have no binary program and shell script which read/proc/$pid/stat, we can know it directly bycat /proc/$pid/status.Signed-off-by Chunguang Wu <[email protected]>--- Documentation/filesystems/proc.rst | 2 ++ fs/proc/array.c | 7 +++++++ 2 files changed, 9 insertions(+)Documentation/filesystems/proc.rst +1
-0@@ -179,6 +179,7 @@ read the file /proc/PID/status:: Gid: 100 100 100 100 FDSize: 256 Groups: 100 14 16 + Kthread: 0 VmPeak: 5004 kB VmSize: 5004 kB VmLck: 0 kB
Documentation/filesystems/proc.rst It's slow but very precise. · line 263
Quoted 7 lines
Documentation/filesystems/proc.rst +1
-0@@ -256,6 +257,7 @@ It's slow but very precise. NSpid descendant namespace process ID hierarchy NSpgid descendant namespace process group ID hierarchy NSsid descendant namespace session ID hierarchy + Kthread kernel thread flag, 1 is yes, 0 is no VmPeak peak virtual memory size VmSize total program size VmLck locked memory size
The Documentation changes look good, except that they may need to be moved if you do the changes indicated below.
Now that I have looked at the rest of the patch:
Quoted 5 lines
fs/proc/array.c +0
-0
fs/proc/array.c int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, · line 443
Quoted 10 lines
fs/proc/array.c +7
-0@@ -434,6 +434,13 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,task_state (m, ns, pid, task); +seq_puts (m,"Kthread:\t" ); +if (task->flags &PF_KTHREAD ) { +seq_puts (m,"1\n" ); + }else { +seq_puts (m,"0\n" ); + } +
I would put that patch fragment inside task_state(), but I'll leave that to others to decide on.
and condense it to one line, e.g.:
seq_puts(m, "Kthread: %c\n", task->flags & PF_KTHREAD ? '1' : '0');
fs/proc/array.c int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, · line 446
Quoted 3 lines
fs/proc/array.c +0
-0if (mm) {task_mem (m, mm);task_core_dumping (m, task);
Please add version info to your future patches.
Thanks.
Signature · 1 line
~Randy