[PATCH] fs/proc: add Kthread flag to /proc/$pid/status

From: Chunguang Wu
Date: Fri Apr 14 2023 - 05:28:20 EST


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 by
`cat /proc/$pid/status`.

Signed-off-by: Chunguang Wu <fullspring2018@xxxxxxxxx>
---
fs/proc/array.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 9b0315d34c58..fde6a0b92728 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -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);
--
2.39.1