How does getrusage() report time spent hibernating?

笑着哭i 提交于 2019-12-11 13:54:32

问题


I am currently using getrusage to tell me how much time I spend in my application's event loop.

I wonder how this will be affected by hibernating. Is hibernation time reported at all? Or perhaps as system time? Is this specified somewhere in Posix or is this system dependent?

Edit Asking the same question for Windows here.


回答1:


I don't think POSIX mentions hibernation anywhere, so it is technically platform dependent.

I can only speak for Linux, but other UNIX variants - and perhaps even Windows - probably behave similarly, since this is what makes most sense.

In Linux, the exact details of what happens under the hood with hibernation are described in Documentation/power/swsusp.txt under the kernel source. In short, user processes are sent a fake signal that causes them to switch to TASK_UNINTERRUPTIBLE state. A process in the TASK_UNINTERRUPTIBLE state is taken out of the run queue and put to sleep until the condition it is waiting for comes true, so time spent in TASK_UNINTERRUPTIBLE is neither counted as user time nor as system time. If you were to measure runtimes with time(1), you would at most see that it contributes to wall clock time.

With getrusage(2), you won't see a difference in any of the reported CPU times because the process wasn't runnable.

So, to answer your question: hibernation time is not reported at all.



来源:https://stackoverflow.com/questions/31246788/how-does-getrusage-report-time-spent-hibernating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!