Skip to contentSkip to conversation

fs/proc: add Kthread flag to /proc/$pid/status

PATCH Andrew Morton 2 participants 2 messages Apr 12, 2023 – Apr 13, 2023 1 message not in the archive VFS

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 9 lines · On Wed, 12 Apr 2023 22:34:02 +0800 Chunguang Wu <[email protected]> wrote:

user can know that a process is kernel thread or not.

...

fs/proc/array.c +0 -0
@@ -434,6 +434,12 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
 
 	task_state(m, ns, pid, task);

fs/proc/array.c int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, · line 445

Quoted 10 lines
fs/proc/array.c +6 -0
 
+	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?

#2 lore raw
Quoted 10 lines · Andrew Morton
Quoted 8 lines · On Wed, 12 Apr 2023 22:34:02 +0800 Chunguang Wu <[email protected]> wrote:

user can know that a process is kernel thread or not.

...

fs/proc/array.c +0 -0
@@ -434,6 +434,12 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
 
Quoted 7 lines

fs/proc/array.c int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, · line 441

Quoted 7 lines
fs/proc/array.c +5 -0
 	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.

Quoted 5 lines

fs/proc/array.c int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, · line 444

Quoted 3 lines
fs/proc/array.c +0 -0
 	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 .

Quoted 4 lines

What is the use case?

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