All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chunguang Wu <fullspring2018@gmail.com>
To: akpm@linux-foundation.org
Cc: adobriyan@gmail.com, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Subject: [PATCH] fs/proc: add Kthread flag to /proc/$pid/status
Date: Fri, 14 Apr 2023 17:27:51 +0800	[thread overview]
Message-ID: <20230414092751.10636-1-fullspring2018@gmail.com> (raw)

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@gmail.com>
---
 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


             reply	other threads:[~2023-04-14  9:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-14  9:27 Chunguang Wu [this message]
2023-04-14 15:17 ` [PATCH] fs/proc: add Kthread flag to /proc/$pid/status Randy Dunlap
  -- strict thread matches above, loose matches on Subject: below --
2023-04-15  8:21 Chunguang Wu
2023-04-15 16:03 ` Randy Dunlap
     [not found] <tencent_3E1CBD85D91AD4CDDCB5F429A3948EB94306@qq.com>
2023-04-12 21:12 ` Andrew Morton
2023-04-13 18:36   ` Alexey Dobriyan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230414092751.10636-1-fullspring2018@gmail.com \
    --to=fullspring2018@gmail.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.