Do we have any ways to retrieve the list of process and threads which are in runnable state(not running state) in ubuntu?

113 Views Asked by At

My requirement is to do dynamic cpu shielding in C program based on the queue length of runnable threads (but not running threads which are waiting for CPU availability) in Realtime operating systems-(say ubuntu with RT linux patch) scenarios. For example, we can consider the system is configured for SCHED_FIFO policy.

I am not able to find any commands to retrieve the number of process which are in wait state, running state, runnable state etc.

Any help is much appreciated.

The command 'PS -T au' shows the state of all 'runnable' as well as 'running' threads as 'R'.

PS -T au

Below is the result I am getting from above command. In this ThreadID-16841, 16842 and 16843 are threads which were created by main process 16840. All the above created threads were showing in R state which denotes Runnable or running.

Instead I would like a linux command or C API to retrieve the number of processes in a runnable state but not running.

USER       PID  SPID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

root       914   914  0.1  1.3 428324 105804 tty7    Rsl+ Oct23   1:27 /usr/lib/xorg/Xorg -core :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten

root       914   925  0.0  1.3 428324 105804 tty7    Ssl+ Oct23   0:04 /usr/lib/xorg/Xorg -core :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten

root      1170  1170  0.0  0.0  23004  1772 tty1     Ss+  Oct23   0:00 /sbin/agetty --noclear tty1 linux

senthil   1979  1979  0.0  0.0  29532  5056 pts/11   Ss   Oct23   0:00 bash

senthil   2032  2032  0.0  0.0  29552  5212 pts/2    Ss   Oct23   0:00 bash

root     16837 16837  0.0  0.0  62092  4132 pts/2    S+   09:37   0:00 sudo ./sigmain

root     16840 16840  0.0  0.0  31108   796 pts/2    Sl+  09:37   0:00 ./sigmain

root     16840 16841 95.9  0.0  31108   796 pts/2    Rl+  09:37   9:01 ./sigmain

root     16840 16842 95.9  0.0  31108   796 pts/2    Rl+  09:37   9:01 ./sigmain

root     16840 16843 95.9  0.0  31108   796 pts/2    Rl+  09:37   9:01 ./sigmain

senthil  17225 17225  0.0  0.0  44432  3364 pts/11   R+   09:46   0:00 ps -T au
0

There are 0 best solutions below