linux下多定时器源码
来源:互联网 发布:linux网络相关命令 编辑:程序博客网 时间:2024/06/05 15:28
#include <time.h>
#include <signal.h>
#include<stdio.h>
#include<stdlib.h>
#include <unistd.h>
#include <string.h>
void handle(union sigval v)
{
time_t t;
char p[32];
time(&t);
strftime(p, sizeof(p), "%T", localtime(&t));
printf("%s thread %lu, val = %d, signal captured.\n", p, pthread_self(), v.sival_int);
return;
}
void handlec(union sigval v) //定时器2产生信号时调用的处理函数
{
time_t t;
char p[32];
time(&t);
strftime(p, sizeof(p), "%T", localtime(&t));
printf("%s thread %lu, val = %d, signal captured.\n", p, pthread_self(), v.sival_int);
return;
}
int main()
{
struct sigevent evp,evc;
struct itimerspec ts,tsc;
timer_t timer,timerc;
int ret,retc;
/*----------------------定时器2---------------------------------------*/
memset (&evc, 0, sizeof (evc));
evc.sigev_value.sival_ptr = &timerc;
evc.sigev_notify = SIGEV_THREAD;
evc.sigev_notify_function = handlec;
evc.sigev_value.sival_int = 2; //作为handle()的参数
retc = timer_create(CLOCK_REALTIME, &evc, &timerc);
if( retc)
perror("timerc_create");
tsc.it_interval.tv_sec = 5;
tsc.it_interval.tv_nsec = 0;
tsc.it_value.tv_sec = 3;
tsc.it_value.tv_nsec = 0;
retc = timer_settime(timerc, TIMER_ABSTIME, &tsc, NULL);
if( retc )
perror("timerc_settime");
/*---------------------定时器4-------------------------------------*/
memset (&evp, 0, sizeof (evp));
evp.sigev_value.sival_ptr = &timer;
evp.sigev_notify = SIGEV_THREAD;
evp.sigev_notify_function = handle;
evp.sigev_value.sival_int = 4; //作为handle()的参数
ret = timer_create(CLOCK_REALTIME, &evp, &timer);
if( ret)
perror("timer_create");
ts.it_interval.tv_sec = 1;
ts.it_interval.tv_nsec = 0;
ts.it_value.tv_sec = 3;
ts.it_value.tv_nsec = 0;
ret = timer_settime(timer, TIMER_ABSTIME, &ts, NULL);
if( ret )
perror("timer_settime");
while(1);
}
#include <signal.h>
#include<stdio.h>
#include<stdlib.h>
#include <unistd.h>
#include <string.h>
void handle(union sigval v)
{
time_t t;
char p[32];
time(&t);
strftime(p, sizeof(p), "%T", localtime(&t));
printf("%s thread %lu, val = %d, signal captured.\n", p, pthread_self(), v.sival_int);
return;
}
void handlec(union sigval v) //定时器2产生信号时调用的处理函数
{
time_t t;
char p[32];
time(&t);
strftime(p, sizeof(p), "%T", localtime(&t));
printf("%s thread %lu, val = %d, signal captured.\n", p, pthread_self(), v.sival_int);
return;
}
int main()
{
struct sigevent evp,evc;
struct itimerspec ts,tsc;
timer_t timer,timerc;
int ret,retc;
/*----------------------定时器2---------------------------------------*/
memset (&evc, 0, sizeof (evc));
evc.sigev_value.sival_ptr = &timerc;
evc.sigev_notify = SIGEV_THREAD;
evc.sigev_notify_function = handlec;
evc.sigev_value.sival_int = 2; //作为handle()的参数
retc = timer_create(CLOCK_REALTIME, &evc, &timerc);
if( retc)
perror("timerc_create");
tsc.it_interval.tv_sec = 5;
tsc.it_interval.tv_nsec = 0;
tsc.it_value.tv_sec = 3;
tsc.it_value.tv_nsec = 0;
retc = timer_settime(timerc, TIMER_ABSTIME, &tsc, NULL);
if( retc )
perror("timerc_settime");
/*---------------------定时器4-------------------------------------*/
memset (&evp, 0, sizeof (evp));
evp.sigev_value.sival_ptr = &timer;
evp.sigev_notify = SIGEV_THREAD;
evp.sigev_notify_function = handle;
evp.sigev_value.sival_int = 4; //作为handle()的参数
ret = timer_create(CLOCK_REALTIME, &evp, &timer);
if( ret)
perror("timer_create");
ts.it_interval.tv_sec = 1;
ts.it_interval.tv_nsec = 0;
ts.it_value.tv_sec = 3;
ts.it_value.tv_nsec = 0;
ret = timer_settime(timer, TIMER_ABSTIME, &ts, NULL);
if( ret )
perror("timer_settime");
while(1);
}
- linux下多定时器源码
- 关于linux下定时器,多定时器
- Linux下多定时器的实现
- linux下多定时器的实现
- Linux下多定时器的实现
- linux下如何实现多个定时器
- linux下精密定时器
- Linux下的定时器
- Linux下定时器使用
- Linux下定时器使用
- Linux下的定时器
- Linux下定时器使用
- Linux下的定时器
- Linux下定时器使用
- linux下精密定时器
- Linux下的定时器
- linux 下的定时器。
- Linux下的定时器
- ubuntu安装jdk全过程(仅供参考)
- 初识MD5
- jqGrid 学习笔记--数据异步加载方法 随笔1
- .configure/make/make install的作用
- android中SDK的DigitalClock存在内存泄漏
- linux下多定时器源码
- ORACLE----触发器,存储过程及JOB
- Page is already covered by another Data Binder. Cannot be covered by this Data Binder again
- (转)使用GradientFill实现控件颜色渐变
- 网页中插入视频播放代码全集
- 【进程通信】消息队列简单例子
- MySQL、SQL Server 、 Oracle、Access的sql语句区别
- 【总结】java命令解析以及编译器,虚拟机如何定位类
- WLAN学习 ap ac dns ssl nal radius http dhcp aaa chap...