1

Basically 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)?

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
JMW
  • 7,151
  • 9
  • 30
  • 37

1 Answers1

5

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.

sarnold
  • 102,305
  • 22
  • 181
  • 238
  • thanks :D that a very good information, but in my linux (ubuntu 8.10) all i see is: se.exec_start se.vruntime se.sum_exec_runtime nr_switches nr_voluntary_switches nr_involuntary_switches se.load.weight policy prio clock-delta – JMW Feb 28 '11 at 11:46
  • @JMW, I might use `nr_switches` then -- it'll increment for every context switch -- maybe only once for process -> kernel -> process, maybe once for each process -> kernel, kernel -> process. Either way, if it increases, control was probably returned to the program. – sarnold Mar 02 '11 at 09:11