首页 > 其他分享 >posix timer

posix timer

时间:2024-10-10 14:23:29浏览次数:1  
标签:sev tv timer posix value include its

 

/*
 * timr.c
 *
 *  Created on: May 11, 2024
 *      Author: 
 */


#include <signal.h>
       #include <stdint.h>
       #include <stdio.h>
       #include <stdlib.h>
       #include <time.h>
       #include <unistd.h>

       #define CLOCKID CLOCK_REALTIME
       #define SIG SIGRTMIN

       #define errExit(msg)    do { perror(msg); exit(EXIT_FAILURE); \
                               } while (0)



void timer_callback(union sigval v)
{
    printf("timer_callback!\n");
}

int main(void)
{
    timer_t timerid;
    struct sigevent sev;
    sev.sigev_notify = SIGEV_THREAD;
    sev.sigev_value.sival_ptr = &timerid;
    sev.sigev_notify_function = timer_callback;
    sev.sigev_notify_attributes = NULL;

    if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1) {
        perror("timer_create");
        return 1;
    }

    struct itimerspec its;
    its.it_value.tv_sec =0;
    its.it_value.tv_nsec = 9;
    its.it_interval.tv_sec = 3;
    its.it_interval.tv_nsec = its.it_value.tv_nsec;

    if (timer_settime(timerid, 0, &its, NULL) == -1) {
        perror("timer_settime");
        return 1;
    }
    while(1);
}

 

标签:sev,tv,timer,posix,value,include,its
From: https://www.cnblogs.com/tryst/p/18456276

相关文章

  • JAVA基础:FutureTasck 和 Callable、Timer定时任务
    1FutureTasck和Callable是JDK1.5之后,在JUC工具包提供了一个多线程工具类在多线程应用中,a线程可以通过FutureTask和Callable了解b线程是否执行完毕以及b线程执行的结果。可以实现两个线程之间的通信。自定义线程类,实现Callable接口,重写call方法,该方法执行的功能就是......
  • XTimer定时微服务项目
    Xtimer定时微服务项目背景在学校社团中,有给社团成员发送活动通知的任务需求有定期执行某项任务的需求,比如每周末举办一次线下活动,每个月举行一次团建再比如,我有一个任务需要设置定时发布定时微服务调研对比方案不足点JavaTimer单线程,任务堆积RocketMq可以作为......
  • WPF ListBox ListBoxItemTemplate display image automatically via System.Timers.Ti
    //xaml<Windowx:Class="WpfApp6.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.micr......
  • Linux线程-POSIX信号量与锁以及条件变量
    POSIX信号量POSIX没有元素这个概念相比于SYSTEM-V更简洁,POSIX不一定适用老版本;二者都是系统范畴,都需要手动删除,POSIX相关函数属于线程库,所有编译时需要末尾加上-lpthread选项POSIXPOSIX有名信号量主要用于进程间通信创建成功后,器特殊文件存放路径:/dev/shm/POSIX无名......
  • 【线程】POSIX信号量---基于环形队列的生产消费者模型
    信号量概念这篇文章是以前写的,里面讲了 SystemV的信号量的概念,POSIX信号量和SystemV信号量作用相同,都是用于同步操作,达到无冲突的访问共享资源目的。但POSIX可以用于线程间同步。信号量的概念POSIX信号量的接口初始化信号量参数:pshared:0表示线程间共享,非0表示进程......
  • WPF Image show picture in high resolution periodically via System.Timers.Timer
    <Windowx:Class="WpfApp411.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • WPF Image automatically display image via System.Timers.Timer ,pause and resume,
    <Windowx:Class="WpfApp408.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • WPF StatusBar update periodically via System.Timers.Timer
    //xaml<Windowx:Class="WpfApp406.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......
  • ListBox show image and refresh automatically via System.Timers.Timer per 1 milli
    <Windowx:Class="WpfApp403.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • Intel Watchdog Timer Driver (Intel WDT) 是一种硬件监控驱动程序,用于系统监控和故障
    IntelWatchdogTimerDriver(IntelWDT)是一种硬件监控驱动程序,用于系统监控和故障恢复。这个驱动程序的主要功能是提供硬件级的看门狗定时器,用于监测系统的健康状况并在系统出现故障时进行恢复或重启。以下是关于IntelWDT驱动程序的一些关键点:1. 功能与目的硬件监控:I......