Skip to content

Commit 522dc4e

Browse files
Chunguang Wuakpm00
authored andcommitted
fs/proc: add Kthread flag to /proc/$pid/status
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`. Link: https://lkml.kernel.org/r/20230416052404.2920-1-fullspring2018@gmail.com Signed-off-by: Chunguang Wu <fullspring2018@gmail.com> Reviewed-by: Randy Dunlap <rdunlap@infradead.org> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 3647ebc commit 522dc4e

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

Documentation/filesystems/proc.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ read the file /proc/PID/status::
179179
Gid: 100 100 100 100
180180
FDSize: 256
181181
Groups: 100 14 16
182+
Kthread: 0
182183
VmPeak: 5004 kB
183184
VmSize: 5004 kB
184185
VmLck: 0 kB
@@ -256,6 +257,7 @@ It's slow but very precise.
256257
NSpid descendant namespace process ID hierarchy
257258
NSpgid descendant namespace process group ID hierarchy
258259
NSsid descendant namespace session ID hierarchy
260+
Kthread kernel thread flag, 1 is yes, 0 is no
259261
VmPeak peak virtual memory size
260262
VmSize total program size
261263
VmLck locked memory size

fs/proc/array.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
219219
seq_put_decimal_ull(m, "\t", task_session_nr_ns(p, pid->numbers[g].ns));
220220
#endif
221221
seq_putc(m, '\n');
222+
223+
seq_printf(m, "Kthread:\t%c\n", p->flags & PF_KTHREAD ? '1' : '0');
222224
}
223225

224226
void render_sigset_t(struct seq_file *m, const char *header,

0 commit comments

Comments
 (0)