2

I know how to hide kernel threads from ps:

/bin/ps --pid 2 --ppid 2 --deselect -o user:10,pid,stat,pcpu,pmem,tty,start_time,cmd

and I know how to show only processes owned by root:

/bin/ps -U root -o user:10,pid,stat,pcpu,pmem,tty,start_time,cmd

but how do I show only processes owned by root, while excluding kernel threads?

Combining the two above commands does not work:

/bin/ps --pid 2 --ppid 2 --deselect -U root -o user:10,pid,stat,pcpu,pmem,tty,start_time,cmd
Martin Vegter
  • 358
  • 75
  • 236
  • 411
  • Logical since deselect will apply to both pid, ppid and U specifications. I suggest you find another way to ignore kernel threads than using pid and ppid selectors deselected @StépaheChazelas answer in https://unix.stackexchange.com/questions/78583/can-ps-display-only-non-kernel-processes-on-linux could possibly help – MC68020 Sep 26 '22 at 16:55

1 Answers1

2

You can always do the selection by hand using awk:

ps -o user:10,pid,stat,pcpu,pmem,tty,start_time,cmd -p $(
  ps -Ao pid= -o sid= -o uid= | awk '$2 && ! $3 {print $1}'
)

Here checking for the session id which is 0 for kernel threads.