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
1
  • 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 unix.stackexchange.com/questions/78583/… could possibly help
    – MC68020
    Commented Sep 26, 2022 at 16:55

1 Answer 1

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.

1
  • does this show real or effective uid root processes ? Commented Sep 26, 2022 at 18:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .