Find out how long a process is sleeping in Linux? [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this questionBasically I want to have all processes that have been sleeping for more than one hour.
I know that there is etime in ps, but sadly it shows the overall lifetime.
How can this be done under linux (preferably with ps)?
The /proc/pid/sched
file contains a metric ton of scheduling data:
$ cat sched
bash (2192, #threads: 1)
---------------------------------------------------------
se.exec_start : 294360163.632873
se.vruntime : 17694.720927
se.sum_exec_runtime : 2643.766318
se.statistics.wait_start : 0.000000
se.statistics.sleep_start : 294360163.632873
se.statistics.block_start : 0.000000
se.statistics.sleep_max : 34689385.720961
se.statistics.block_max : 11337.665116
se.statistics.exec_max : 7.657145
se.statistics.slice_max : 0.550257
se.statistics.wait_max : 7.464190
se.statistics.wait_sum : 37.981183
se.statistics.wait_count : 13774
se.statistics.iowait_sum : 1556.105204
se.statistics.iowait_count : 278
sched_info.bkl_count : 0
se.nr_migrations : 2816
se.statistics.nr_migrations_cold : 0
se.statistics.nr_failed_migrations_affine: 0
se.statistics.nr_failed_migrations_running: 335
se.statistics.nr_failed_migrations_hot: 14
se.statistics.nr_forced_migrations : 0
se.statistics.nr_wakeups : 13471
se.statistics.nr_wakeups_sync : 3293
se.statistics.nr_wakeups_migrate : 2532
se.statistics.nr_wakeups_local : 655
se.statistics.nr_wakeups_remote : 12816
se.statistics.nr_wakeups_affine : 78
se.statistics.nr_wakeups_affine_attempts: 9452
se.statistics.nr_wakeups_passive : 0
se.statistics.nr_wakeups_idle : 0
avg_atom : 0.196329
avg_per_cpu : 0.938837
nr_switches : 13466
nr_voluntary_switches : 13447
nr_involuntary_switches : 19
se.load.weight : 1024
policy : 0
prio : 120
clock-delta : 95
I suggest reading through the /proc/*/sched
files looking for se.statistics.nr_wakeups
or se.statistics.wait_count
lines that don't change for an hour. I don't know off-hand which one would give you 'better' results, but try both :) and see which one gives you answers like you expect.
精彩评论