專(zhuān)注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)濉溪免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了1000+企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。>編寫(xiě)一個(gè)程序(庫(kù)),實(shí)現(xiàn)定時(shí)器(計(jì)時(shí)器)的功能,它能為用戶(hù)提供在同一進(jìn)程中多次使用的定時(shí)器。這里要求用信號(hào)來(lái)實(shí)現(xiàn)。 示例代碼如下: #include <stdio.h> #include <time.h> #include <sys/time.h> #include <stdlib.h> #include <signal.h> static int time_count = 0; static struct itimerval oldtv; void set_timer() { struct itimerval itv; itv.it_interval.tv_sec = 1; itv.it_interval.tv_usec = 0; itv.it_value.tv_sec = 1; itv.it_value.tv_usec = 0; setitimer(ITIMER_REAL, &itv, &oldtv); } void signal_handler(int m) { time_count ++; printf("%d\n", time_count); } int main() { signal(SIGALRM, signal_handler); set_timer(); while(1){ if(time_count==5) { printf("time_count = 5\n"); time_count=0; } } return 1; }
網(wǎng)站名稱(chēng):LinuxC語(yǔ)言的定時(shí)器使用方法-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)地址:http://chinadenli.net/article22/shcjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、搜索引擎優(yōu)化、響應(yīng)式網(wǎng)站、微信公眾號(hào)、網(wǎng)站內(nèi)鏈、品牌網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容