Jiwu Bu

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  32 随笔 :: 0 文章 :: 25 评论 :: 0 Trackbacks
函数原型 int setitimer(int which, const struct itimerval *value,
                     struct itimerval *ovalue);

       The  system  provides each process with three interval timers, each decrementing in a distinct time domain.  When any timer expires, a
       signal is sent to the process, and the timer (potentially) restarts.

       ITIMER_REAL    decrements in real time, and delivers SIGALRM upon expiration.

       ITIMER_VIRTUAL decrements only when the process is executing, and delivers SIGVTALRM upon expiration.

       ITIMER_PROF    decrements both when the process executes and when the system is executing on behalf  of  the  process.   Coupled  with
                      ITIMER_VIRTUAL, this timer is usually used to profile the time spent by the application in user and kernel space.  SIG-
                      PROF is delivered upon expiration.

       Timer values are defined by the following structures:

            struct itimerval {
                struct timeval it_interval; /* next value */
                struct timeval it_value;    /* current value */
            struct timeval {
                long tv_sec;                /* seconds */
                long tv_usec;               /* microseconds */

#include <stdio.h>

void PrintMsg(int Num)
"%s\n""Hello World");


int main(int argc, char* argv[])
    signal(SIGALRM, PrintMsg);

struct itimerval tick;
= 10;  //十秒钟后将启动定时器
    tick.it_value.tv_usec = 0;
    tick.it_interval.tv_usec = 0;

    int ret = setitimer(ITIMER_REAL, &tick, NULL);

if ( ret != 0)
"Set timer error. %s \n", strerror(errno) );

return -1;



return 0;

posted on 2009-11-16 13:50 bujiwu 阅读(2553) 评论(0)  编辑 收藏 引用 所属分类: Linux

【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理