Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C中的Perl alarm()等价物?_C_Linux_Perl_Alarm - Fatal编程技术网

C中的Perl alarm()等价物?

C中的Perl alarm()等价物?,c,linux,perl,alarm,C,Linux,Perl,Alarm,在Linux的C语言中,Perl的alarm()等价物是什么?当然,Windows中没有本机的报警函数,但是Perl提供了一种解决方法,我对此并不感兴趣 对于那些不知道报警的人: 编辑:我实际上需要毫秒精度的警报。我可以在线程(多线程应用程序)中使用它。类似于: unsigned int alarm (unsigned int secs, unsigned int usecs) { struct itimerval old, new; new.it_interval.tv_usec

在Linux的C语言中,Perl的
alarm()
等价物是什么?当然,Windows中没有本机的
报警
函数,但是Perl提供了一种解决方法,我对此并不感兴趣

对于那些不知道报警的人:

编辑:我实际上需要毫秒精度的警报。我可以在线程(多线程应用程序)中使用它。

类似于:

unsigned int alarm (unsigned int secs, unsigned int usecs) {
   struct itimerval old, new;
   new.it_interval.tv_usec = 0;
   new.it_interval.tv_sec = 0;

   // usecs should always be < 1000000
   secs += usecs / 1000000;
   usecs = usecs % 1000000;

   // set the alarm timer
   new.it_value.tv_usec = (long int) usecs;
   new.it_value.tv_sec = (long int) secs;

   // type ITIMER_REAL for wallclock timer
   if (setitimer (ITIMER_REAL, &new, &old) < 0)
     return 0;
   else
     return old.it_value.tv_sec;
 }
unsigned int报警(unsigned int secs,unsigned int usecs){
结构itimerval旧,新;
new.it\u interval.tv\u usec=0;
new.it_interval.tv_sec=0;
//usecs应始终小于1000000
秒+=usecs/1000000;
usecs=usecs%1000000;
//设置闹钟定时器
new.it_value.tv_usec=(long int)usecs;
new.it_value.tv_sec=(长整数)秒;
//为wallclock计时器键入ITIMER\u REAL
如果(设置ITIMER(ITIMER_真实、新和旧)<0)
返回0;
其他的
返回old.it_value.tv_sec;
}

请参阅:

这不只是吗?实时计时器系统调用:timer\u create()、setitimer()、timer\u delete()似乎就是您想要的。timer_create()手册页有一个示例。,