Timers 101, Part 2

May 9, 2002, 11:00 PM —  ITworld — 

Interval Timers
An interval timer delivers signals to a process on a regular basis.
Linux assigns three interval timers to a process, each of which delivers
a distinct signal. The following symbolic constants identify these
timers:

* ITIMER_REAL -- This is the so-called "real-time timer", or a timer
that functions like a clock on the wall. It delivers a SIGALRM
signal to a process on a periodical basis, regardless of whether
the process is executing or not.
* ITIMER_VIRTUAL -- This timer counts only the time during which the
process is executing, excluding the time spent in syscalls. It
delivers a SIGVTALRM signal.
* ITIMER_PROF -- Counts the time during which the process is
executing, including syscalls' execution time. It excludes any
time spent executing interrupts. This timer delivers a SIGPROF
signal.

The combination of ITIMER_VIRTUAL and ITIMER_PROF is often used in code
profilers. You shouldn't use the alarm() and sleep() syscalls in a
program that uses an ITIMER_REAL timer because it conflicts with the
signals delivered by these syscalls.

Signal Generation
Each of these timers will issue its distinct signal within one system
clock tick (a hundredth of second on most hardware architectures) once
the timer has expired. If the process is currently executing, the
SIGALRM and SIGPROF signals will be delivered immediately. Otherwise,
they will be delivered as soon as possible. Since SIGVTALRM is generated
only when the process is running, it will always be delivered
immediately.

Setting and Examining Timers
The struct itimerval is used for setting and querying interval timers:

struct itimerval
{
struct timeval it_interval;
struct timeval it_value;
};

Recall that struct timeval is declared as follows:

struct timeval
{
int tv_sec; /*seconds*/
int tv_usec; /*microseconds*/
};

it_interval contains the amount of time between signals. it_value is the
amount of time left until the next signal is issued. To query a timer,
use the getitimer function:

int getitimer(int timertype, struct itimerval * tv);

The first argument is one of the three interval timers listed above. The
function fills tv with the current state of the timertype.

int setitimer(int timertype,
struct itimerval * new,
struct itimerval * old);

This function sets the timer timertype to newtimer. If old isn't NULL,
it's filled with the previous setting. To disable a timer immediately,
set its it_value to zero. To disable after the next signal, set
it_interval to zero.

» posted by ITworld staff

ITworld

Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world

I like it!
Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
peer-to-peer

jfruh
Apple syncing patent can't come soon enough

pasmith
New Twitter features borrow from 3rd party clients

Esther Schindler
Open Source Changes the Software Acquisition Process

mikelgan
How to set up continuous podcast play on the new iTunes

David Strom
Five important Windows 7 mobility features

sjvn
Guard your Wi-Fi for your own sake                        

Sandra Henry-Stocker
Grepping on Whole Words

 

Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325

Join the conversation here

The Daily Tip

The Daily TipQuick, practical advice for IT pros. Made fresh daily.

Hot tips:

Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.

Newsletters

Subscribe to ITWORLD TODAY and receive the latest IT news and analysis.

I would like to receive offers via email from ITworld partners.
By clicking submit you agree to the terms and conditions outlined in ITworld's privacy policy.
Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

Marketplace