用户空间中的 Linux C/C++ 定时器信号处理程序 [英] Linux C/C++ Timer signal handler in userspace

查看:20
本文介绍了用户空间中的 Linux C/C++ 定时器信号处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要 C/C++ linux 中的一个函数(例如信号处理程序),它每 'n' 毫秒被激活一次.我如何设置信号等...以毫秒分辨率注册到计时器事件.

I need a function(eg signal handler) in C/C++ linux that gets activated every 'n' milliseconds. How do I setup signals etc...to register to timer events at the millisecond resolution.

准确度不是很关键,但需要在百毫秒左右.

Accuracy is not super critical, but need within hundred ms or so.

我是 Linux 新手,我真的不知道从哪里开始.

I am new to linux and I really don't know where to start.

推荐答案

setitimer(2) 是一个好的开始,但你真的想要异步处理信号吗?否则,你可以有一个带有 select(2)poll(2) 的主循环和适当的超时.

setitimer(2) is a good start, but do you really want to go asynchronous with signals? Otherwise, you could have a main loop with select(2) or poll(2) and an appropiate timeout.

这篇关于用户空间中的 Linux C/C++ 定时器信号处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆