1

I have a C program on linux. During execution of my program, I want to make some decisions if the process is facing scheduling delay above a threshold.

Any suggestion on how I find this statistic ?

P.S.: By scheduling delay I mean time spent by the process waiting to be scheduled i.e. time spent in the scheduler queue.

L Lawliet
  • 2,565
  • 4
  • 26
  • 35
  • 1
    What do you mean by "scheduling delay"? Can you please elaborate? – Some programmer dude Sep 12 '14 at 18:49
  • I meant how much time the process is spending in scheduler queue, i.e. time spent waiting to be scheduled. – L Lawliet Sep 12 '14 at 18:54
  • 1
    @Siddharth: you should *edit your question* to improve it instead of answering in comments. – Basile Starynkevitch Sep 12 '14 at 18:55
  • @Siddharth - Its the ready queue in which the process stands while waiting for its turn, and the technical name of scheduling delay is "waiting time". Some of the factors on which waiting time depends are : 1. Scheduling algorithm used. 2. Number of processes currently running. Check out this link.. http://stackoverflow.com/questions/10265162/the-meaning-of-real-user-and-sys-in-output-of-linux-time-command – Abhishek Choubey Sep 12 '14 at 20:05
  • @Abhishek please read the question. I know what factors cause scheduling delays. The question was how to figure out the delay value. Anyway Franco answered that already. – L Lawliet Sep 12 '14 at 21:12

2 Answers2

2

You could set a timer to go off, say every minute, or whatever interval seems appropriate and then gather stats with getrusage() and based on those results (the difference between successive values), you could make your decision then

John Hascall
  • 9,176
  • 6
  • 48
  • 72
2

The time() function allows you to measure the "wall clock" time: http://linux.die.net/man/2/time On the other side, the clock() function allows you to measure the CPU time used by your process: http://linux.die.net/man/3/clock

By subtracting the two, you can get an approximation of what you asked for.

PS: for more accurate measurements (time has a second resolution) you can use clock_gettime: http://linux.die.net/man/3/clock_gettime

Giulio Franco
  • 3,170
  • 15
  • 18