Chinaunix首页 | 论坛 | 博客
  • 博客访问: 501747
  • 博文数量: 76
  • 博客积分: 2535
  • 博客等级: 少校
  • 技术积分: 3130
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-22 11:26
个人简介

京都医院http://www.fjzzled.com/杭州京都医院

文章分类

全部博文(76)

文章存档

2011年(25)

2010年(51)

我的朋友

分类: 嵌入式

2011-02-15 22:05:02

#include     // for printf()
#include    // for pause()
#include    // for signal()
#include    // for memset()
#include // struct itimeral. setitimer()
#include
void printMsg(int);
int main() {
  // Get system call result to determine successful or failed
  int res = 0;
  pthread_t a;
  // Register printMsg to SIGALRM
  signal(SIGALRM, pthread_create(&a,NULL,(void*)printMsg,NULL));
 
  struct itimerval tick;
  // Initialize struct
  memset(&tick, 0, sizeof(tick));
  // Timeout to run function first time
  tick.it_value.tv_sec = 1;  // sec
  tick.it_value.tv_usec =0 ; // micro sec.
  // Interval time to run function
  tick.it_interval.tv_sec = 1;
  tick.it_interval.tv_usec =0 ;
  // Set timer, ITIMER_REAL : real-time to decrease timer,
  //                          send SIGALRM when timeout
  res = setitimer(ITIMER_REAL, &tick, NULL);
  if (res) {
    printf("Set timer failed!!\n");
  }
  // Always sleep to catch SIGALRM signal
  while(1) {
     pause();
  }
  return 0 ; 
}
void printMsg(int num) {
  printf("%s","Hello World!!\n");
}
 
阅读(1704) | 评论(1) | 转发(1) |
给主人留下些什么吧!~~

chinaunix网友2011-03-06 17:47:06

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com