2

How can I list processes that are busy in a system call? Is there a way to find it out with the command top? I couldn't find any appropriate option in the man pages.

2

A process that's currently running in kernel mode, i.e. that is busy in a system call, is in state D (as opposed to R for running in user mode, or S for sleeping, i.e. in a system call but blocked on something).

This doesn't distinguish between a process that's doing computation on the CPU while in kernel mode and a process that's waiting on some hardware with signals disabled (the strict definition of uninterruptible sleep). I don't think Linux exposes this distinction anywhere. Computation on the CPU while in kernel mode rarely lasts long anyway.

The top version in Linux procps lists the process state. It doesn't seem to have an option to list only processes in state D, but you can use the i key or the -i command line option to hide all processes that remained idle since the last screen update, which will typically leave less than a screenful.

If you just want to list the PIDs, you can filter the output of ps.

ps -o state=,pid= | sed -n 's/^D //p'

On a system that isn't doing heavy I/O, it's to be expected that most of the time, this will list zero processes.

-1

According to the source code, it is not possible to do that with top.

Nevertheless, top has a -p parameter which allows you to tell it to watch only certain PIDs. Unfortunately this one is also limited to 20 parameters and the kernel could easily have more than 20 processes running.

I created a two line script to test that out:

kprocs=$(ls -l /proc/*/exe | grep -v " -> " | cut -d "/" -f 3)
top -c -p $(echo ${kprocs} | sed 's/ /,/g')

In case you where wandering I am detecting the kernel processes by looking at which links are not pointing to a binary on the disk.

  • What you're doing here is looking for kernel threads, which is not what I understand by “processes currently running in kernel mode”. – Gilles Mar 25 '16 at 23:10
  • as Gilles mentioned I don't want the system threads, but the processes which are busy in system calls – jam Mar 26 '16 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.