* [PATCH v2] fs/proc: add Kthread flag to /proc/$pid/status
@ 2023-04-16 5:24 Chunguang Wu
2023-04-16 5:52 ` Randy Dunlap
0 siblings, 1 reply; 2+ messages in thread
From: Chunguang Wu @ 2023-04-16 5:24 UTC (permalink / raw)
To: akpm, corbet; +Cc: adobriyan, rdunlap, linux-kernel, linux-fsdevel, linux-doc
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>
---
Documentation/filesystems/proc.rst | 2 ++
fs/proc/array.c | 2 ++
2 files changed, 4 insertions(+)
diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst
index 9d5fd9424e8b..8a563684586c 100644
--- a/Documentation/filesystems/proc.rst
+++ b/Documentation/filesystems/proc.rst
@@ -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
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 9b0315d34c58..425824ad85e1 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -219,6 +219,8 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
seq_put_decimal_ull(m, "\t", task_session_nr_ns(p, pid->numbers[g].ns));
#endif
seq_putc(m, '\n');
+
+ seq_printf(m, "Kthread:\t%c\n", p->flags & PF_KTHREAD ? '1' : '0');
}
void render_sigset_t(struct seq_file *m, const char *header,
--
2.39.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] fs/proc: add Kthread flag to /proc/$pid/status
2023-04-16 5:24 [PATCH v2] fs/proc: add Kthread flag to /proc/$pid/status Chunguang Wu
@ 2023-04-16 5:52 ` Randy Dunlap
0 siblings, 0 replies; 2+ messages in thread
From: Randy Dunlap @ 2023-04-16 5:52 UTC (permalink / raw)
To: Chunguang Wu, akpm, corbet
Cc: adobriyan, linux-kernel, linux-fsdevel, linux-doc
Hi--
On 4/15/23 22:24, Chunguang Wu wrote:
> 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>
LGTM. Thanks.
Reviewed-by: Randy Dunlap <rdunlap@infradead.org>
> ---
> Documentation/filesystems/proc.rst | 2 ++
> fs/proc/array.c | 2 ++
> 2 files changed, 4 insertions(+)
>
> diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst
> index 9d5fd9424e8b..8a563684586c 100644
> --- a/Documentation/filesystems/proc.rst
> +++ b/Documentation/filesystems/proc.rst
> @@ -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
> diff --git a/fs/proc/array.c b/fs/proc/array.c
> index 9b0315d34c58..425824ad85e1 100644
> --- a/fs/proc/array.c
> +++ b/fs/proc/array.c
> @@ -219,6 +219,8 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
> seq_put_decimal_ull(m, "\t", task_session_nr_ns(p, pid->numbers[g].ns));
> #endif
> seq_putc(m, '\n');
> +
> + seq_printf(m, "Kthread:\t%c\n", p->flags & PF_KTHREAD ? '1' : '0');
> }
>
> void render_sigset_t(struct seq_file *m, const char *header,
--
~Randy
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-04-16 5:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-16 5:24 [PATCH v2] fs/proc: add Kthread flag to /proc/$pid/status Chunguang Wu
2023-04-16 5:52 ` Randy Dunlap
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox