All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] fs/proc: add Kthread flag to /proc/$pid/status
       [not found] <tencent_3E1CBD85D91AD4CDDCB5F429A3948EB94306@qq.com>
@ 2023-04-12 21:12 ` Andrew Morton
  2023-04-13 18:36   ` Alexey Dobriyan
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2023-04-12 21:12 UTC (permalink / raw)
  To: Chunguang Wu; +Cc: linux-kernel, linux-fsdevel, Alexey Dobriyan

On Wed, 12 Apr 2023 22:34:02 +0800 Chunguang Wu <aman2008@qq.com> wrote:

> user can know that a process is kernel thread or not.
> 
> ...
>
> --- a/fs/proc/array.c
> +++ b/fs/proc/array.c
> @@ -434,6 +434,12 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
>  
>  	task_state(m, ns, pid, task);
>  
> +	if ((mm == NULL) || (task->flags & PF_KTHREAD)) {
> +		seq_puts(m, "Kthread:\tYes\n");
> +	} else {
> +		seq_puts(m, "Kthread:\tNo\n");
> +	}
> +
>  	if (mm) {
>  		task_mem(m, mm);
>  		task_core_dumping(m, task);

Well..   Why is this information useful?  What is the use case?

There are many ways of working this out from the existing output - why
is this change required?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] fs/proc: add Kthread flag to /proc/$pid/status
  2023-04-12 21:12 ` [PATCH] fs/proc: add Kthread flag to /proc/$pid/status Andrew Morton
@ 2023-04-13 18:36   ` Alexey Dobriyan
  0 siblings, 0 replies; 6+ messages in thread
From: Alexey Dobriyan @ 2023-04-13 18:36 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Chunguang Wu, linux-kernel, linux-fsdevel

On Wed, Apr 12, 2023 at 02:12:16PM -0700, Andrew Morton wrote:
> On Wed, 12 Apr 2023 22:34:02 +0800 Chunguang Wu <aman2008@qq.com> wrote:
> 
> > user can know that a process is kernel thread or not.
> > 
> > ...
> >
> > --- a/fs/proc/array.c
> > +++ b/fs/proc/array.c
> > @@ -434,6 +434,12 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
> >  
> >  	task_state(m, ns, pid, task);
> >  
> > +	if ((mm == NULL) || (task->flags & PF_KTHREAD)) {
> > +		seq_puts(m, "Kthread:\tYes\n");
> > +	} else {
> > +		seq_puts(m, "Kthread:\tNo\n");
> > +	}

"mm" check is redundant. PF_KTHREAD should be enough.
If you're doing this, just print 0/1. 

> >  	if (mm) {
> >  		task_mem(m, mm);
> >  		task_core_dumping(m, task);
> 
> Well..   Why is this information useful?

I want to add: for a shell script.
Real programs can read /proc/*/stat .

> What is the use case?
> 
> There are many ways of working this out from the existing output - why
> is this change required?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] fs/proc: add Kthread flag to /proc/$pid/status
  2023-04-15  8:21 Chunguang Wu
@ 2023-04-15 16:03 ` Randy Dunlap
  0 siblings, 0 replies; 6+ messages in thread
From: Randy Dunlap @ 2023-04-15 16:03 UTC (permalink / raw)
  To: Chunguang Wu, akpm, corbet
  Cc: adobriyan, linux-kernel, linux-fsdevel, linux-doc

Hi,

On 4/15/23 01:21, 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>
> ---
>  Documentation/filesystems/proc.rst | 2 ++
>  fs/proc/array.c                    | 7 +++++++
>  2 files changed, 9 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

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:

> 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");
> +	}
> +

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');


>  	if (mm) {
>  		task_mem(m, mm);
>  		task_core_dumping(m, task);


Please add version info to your future patches.

Thanks.
-- 
~Randy

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] fs/proc: add Kthread flag to /proc/$pid/status
@ 2023-04-15  8:21 Chunguang Wu
  2023-04-15 16:03 ` Randy Dunlap
  0 siblings, 1 reply; 6+ messages in thread
From: Chunguang Wu @ 2023-04-15  8:21 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                    | 7 +++++++
 2 files changed, 9 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..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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] fs/proc: add Kthread flag to /proc/$pid/status
  2023-04-14  9:27 Chunguang Wu
@ 2023-04-14 15:17 ` Randy Dunlap
  0 siblings, 0 replies; 6+ messages in thread
From: Randy Dunlap @ 2023-04-14 15:17 UTC (permalink / raw)
  To: Chunguang Wu, akpm; +Cc: adobriyan, linux-kernel, linux-fsdevel

Hi--

On 4/14/23 02:27, 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`.
> 

Please update Documentation/filesystems/proc.rst:

(1) the example:
For example, to get the status information of a process, all you have to do is
read the file /proc/PID/status::

and (2): table 1-2

Thanks.

> 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);

-- 
~Randy

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] fs/proc: add Kthread flag to /proc/$pid/status
@ 2023-04-14  9:27 Chunguang Wu
  2023-04-14 15:17 ` Randy Dunlap
  0 siblings, 1 reply; 6+ messages in thread
From: Chunguang Wu @ 2023-04-14  9:27 UTC (permalink / raw)
  To: akpm; +Cc: adobriyan, linux-kernel, linux-fsdevel

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-04-15 16:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <tencent_3E1CBD85D91AD4CDDCB5F429A3948EB94306@qq.com>
2023-04-12 21:12 ` [PATCH] fs/proc: add Kthread flag to /proc/$pid/status Andrew Morton
2023-04-13 18:36   ` Alexey Dobriyan
2023-04-14  9:27 Chunguang Wu
2023-04-14 15:17 ` Randy Dunlap
2023-04-15  8:21 Chunguang Wu
2023-04-15 16:03 ` Randy Dunlap

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.