3

I try to use setitimer(ITIMER_PROF, &tick, NULL) to limit the cpu time consuming by the process. But if the process turns to suspend (in my case ,the process sinks into a dead loop, then the Ubuntu16.04 suspends it and does not wake up it again), the timer cannot kill the process.

If I use:

setitimer(ITIMER_PROF, &tick1, NULL);
setitimer(ITIMER_REAL, &tick2, NULL);

to limit a bigger real time. The man page said the later setitimer will overwrite the former.

How can I use setitimer to limit the process time, both on cpu time and real time ?

wangbo15
  • 191
  • 1
  • 13
  • 2
    Where in the man page does it say that? – fuz Aug 23 '16 at 08:50
  • *`setitimer()` will overwrite the former* <= that would be weird, since one delivers `SIGPROF` and the other `SIGALRM`. The disabling part is relative to the timer (i.e. the `which`) argument. So unless something's seriously broken behind the scenes, your code should work as expected. – dhke Aug 23 '16 at 09:27
  • @dhke Yes, you are right. Thanks ! I mistook the case of 2 calls of `setitimer` using the same `which`. – wangbo15 Aug 23 '16 at 09:48
  • Side note: (this happened to me, because I'm stupid): of course, ITIMER_PROF only increments when the process is actually doing any work. You --of course-- need to perform actual calculation. – dhke Aug 23 '16 at 12:20

0 Answers0