How do I know the last sched time of a process

1.4k views Asked by At

I current run into an issue that a process seems stuck somehow, it just doesn't gets scheduled, the status is always 'S'. I have monitored sched_switch_task trace by debugfs for a while, didn't see the process get scheduled. So I would like to know when is that last time scheduled of this process by kernel?

Thanks a lot.

1

There are 1 answers

1
Dan Cornilescu On BEST ANSWER

It might be possible using the info in /proc/pid#/sched file.

In there you can find these parameters (depending on the OS version, mine is opensuse 3.16.7-21-desktop):

se.exec_start                                :     593336938.868448
...
se.statistics.wait_start                     :             0.000000
se.statistics.sleep_start                    :     593336938.868448
se.statistics.block_start                    :             0.000000

The values represent timestamps relative to the system boot time, but in a unit which may depend on your system (in my example the unit is 0.5 msec, for a total value of ~6 days 20 hours and change).

In the last 3 parameters listed above at most one appears to be non-zero at any time and it I suspect that the respective non-zero value represents the time when it last entered the corresponding state (with the process actively running when all are zero).

So if your process is indeed stuck the non-zero value would have recorded when it got stuck.

Note: this is mostly based on observations and assumptions - I didn't find these parameters documented anywhere, so take them with a grain of salt.

Plenty of other scheduling info in that file, but mostly stats and without documentation difficult to use.