Linux 和 Windows 上的报警功能 ->找不到 Windows 的等效项 ->C [英] alarm function on Linux and Windows -> can't find a equivalent for Windows -> C

查看:29
本文介绍了Linux 和 Windows 上的报警功能 ->找不到 Windows 的等效项 ->C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 Linux 上工作了一段时间并完成了一些 C 程序,现在我需要为 Windows 构建一个应用程序,但不是很容易找到警报功能的替代品(在 signal.h 上找到)..

I have worked for some time now on Linux and done some C programs, and now I need to build an app for windows but is not being easy to find a replacement for the alarm function (found on signal.h)...

问题是,在 Linux 中,当您将警报标志设置为 SIGALRM(如果没有记错的话)时,操作系统将在警报响起时执行某些功能.示例:

The thing is, in Linux, when you set the alarm flag as SIGALRM (if not mistaken), what the OS is going to do is to execute some function when the alarm goes off. Example:

signal(SIGALRM, myfunc);
alarm (2);

在这个例子中,操作系统将每 2 秒调用一次函数 myfunc(在 Windows 中可能是毫秒,但现在不要介意这个细节).

What is going to happen on this example is the OS is going to call the function myfunc every 2 seconds (in windows is going to be miliseconds probably, but don't mind that detail right now).

我已经搜索了一段时间如何在 windows 上做同样的事情(仅使用 windows.h atm),但我找不到替代品(在 msdn 上搜索了数千次),而且,在 windows 上有信号上没有 SIGALRM 标志.h .....

I've searched for some time how to do the same on windows (only using windows.h atm) but I can't find a replacement for that (searched thousands of times on msdn), and, on windows there is no SIGALRM flag on the signal.h.....

我可以在 C 中使用什么来执行与带有 SIGALRM 标志的警报相同的行为?(换句话说,一个允许使用警报或类似功能执行另一个函数的函数).

What can I use in C to do the same behaviour as the alarm with the SIGALRM flag?(In other words, a function that allows to execute another function using an alarm or similar).

推荐答案

检查 MSDN 中的 timeSetEvent.它与 alarm 不完全相同,但可能足够接近.

Check the MSDN for timeSetEvent. It's not exactly the same as alarm, but may be close enough.

这篇关于Linux 和 Windows 上的报警功能 ->找不到 Windows 的等效项 ->C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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