Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] using rusage
- Date: Fri, 20 Jun 2008 08:38:42 +0900
- From: "Josh Glover" <jmglov@example.com>
- Subject: Re: [tlug] using rusage
- References: <78d7dd350806181930i6acda17co682c322d3a7872af@mail.gmail.com> <20080619035005.GB11561@lucky.cynic.net> <78d7dd350806190155k328d24bcjcf61cb707c42045c@mail.gmail.com> <20080619114706.GA15943@lucky.cynic.net>
2008/6/19 Curt Sampson <cjs@example.com>: > On 2008-06-19 17:55 +0900 (Thu), Hung Nguyen Vu wrote: > >> I expected that after a sleep(1), stopTimer() will return 1 seconds > > Well, that's a misunderstanding on your part. > > You asked the OS not to schedule your process for at least one second. > Clearly, you won't be using any CPU during that wait; it's what you > specifically asked for. A couple of comments: 1. The standard way to do *wall clock* timing is to grab a timestamp, go to sleep, grab a new timestamp when you wake up, and subtract the old one from the new one. If you want user or system time, as Curt noted, you won't get any while sleeping. 2. Use nanosleep(2) instead of sleep(2). nanosleep(2) correctly handles signals, and will get you closer to 1.0 seconds than sleep(2) will. Just beware of this if you are doing really hi-res timing: BUGS The current implementation of nanosleep() is based on the normal kernel timer mechanism, which has a resolution of 1/HZ s (see time(7)). There- fore, nanosleep() pauses always for at least the specified time, however it can take up to 10 ms longer than specified until the process becomes runnable again. For the same reason, the value returned in case of a delivered signal in *rem is usually rounded to the next larger multiple of 1/HZ s. -- Cheers, Josh
- Follow-Ups:
- Re: [tlug] using rusage
- From: Curt Sampson
- References:
- [tlug] using rusage
- From: Hung Nguyen Vu
- Re: [tlug] using rusage
- From: Curt Sampson
- Re: [tlug] using rusage
- From: Hung Nguyen Vu
- Re: [tlug] using rusage
- From: Curt Sampson
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] Re: [Was: iptables] Forward multicats
- Next by Date: Re: [tlug] Re: [Was: iptables] Forward multicats
- Previous by thread: Re: [tlug] using rusage
- Next by thread: Re: [tlug] using rusage
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links