最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

c語(yǔ)言定時(shí)器示例分享

 更新時(shí)間:2014年04月28日 10:47:11   作者:  
在linux下開發(fā),使用的是C語(yǔ)言。適用于需要定時(shí)的軟件開發(fā),以系統(tǒng)真實(shí)的時(shí)間來(lái)計(jì)算,它送出SIGALRM信號(hào)。每隔一秒定時(shí)一次

在linux下開發(fā),使用的是C語(yǔ)言。適用于需要定時(shí)的軟件開發(fā),以系統(tǒng)真實(shí)的時(shí)間來(lái)計(jì)算,它送出SIGALRM信號(hào)。每隔一秒定時(shí)一次

c語(yǔ)言定時(shí)器

復(fù)制代碼 代碼如下:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "pthread.h"
#include <netinet/in.h>
#include <signal.h>
#include <sys/time.h>


struct StructOfTimerStatus
{
    unsigned int count;                               //計(jì)數(shù)值
    unsigned int flag;                                //定時(shí)標(biāo)志
}
;

struct StructOfTimer

    struct StructOfTimerStatus      testtime;   //測(cè)試定時(shí)器
}
mytime;

 

void SetTimer(int sec,int usec);
void SigalrmFunc(void);


//定時(shí)器函數(shù)
/*******************************************************************************
* Discription:SIGALRM 信號(hào)響應(yīng)函數(shù);用作定時(shí)器
* Input      :
* Output    :
*******************************************************************************/
void SigalrmFunc(void)
{
    if(mytime.testtime.count++>20)      //定時(shí)1秒,20*50000=1s
    {
        mytime.testtime.flag=1;
        mytime.testtime.count=0;
    }
}


void SetTimer(int sec,int usec)
{
    struct itimerval value,ovalue;
    signal(SIGALRM,(void *)SigalrmFunc);

    value.it_value.tv_sec = sec;
    value.it_value.tv_usec = usec;
    value.it_interval.tv_sec = sec;
    value.it_interval.tv_usec = usec;

    setitimer(ITIMER_REAL,&value,&ovalue); 
}

int main(int argc, char **argv)
{
    SetTimer(0, 50000);
    while(1)
    {
        if(mytime.testtime.flag == 1)
        {
            mytime.testtime.flag = 0;
            system("clear");
            printf("Timing success\n");
        }
    }
    return 0;
}

相關(guān)文章

最新評(píng)論

南开区| 莱芜市| 洛宁县| 永福县| 射阳县| 安塞县| 宿松县| 永昌县| 乾安县| 江安县| 涟水县| 蒲城县| 凤台县| 称多县| 公主岭市| 巴南区| 张家川| 南溪县| 于田县| 衡阳县| 斗六市| 长春市| 新源县| 郴州市| 五华县| 咸阳市| 东丽区| 黄大仙区| 奉节县| 夏河县| 正镶白旗| 常德市| 涿州市| 广水市| 临漳县| 布尔津县| 清徐县| 宁河县| 新营市| 视频| 阿拉善盟|