訊號處理函式 1 alarm定時器

2021-09-09 03:38:30 字數 987 閱讀 8859

定義:

unsigned int alarm(unsigned int seconds);

表頭檔案:

#include

說明:

alarm()用來設定訊號sigalrm(14)在經過引數seconds指定的秒數後傳送給目前的程序。如果引數seconds 為0, 則之前設定的鬧鐘會被取消, 並將剩下的時間返回。

返回值:

返回之前鬧鐘的剩餘秒數, 如果之前未設鬧鐘則返回0。

signal, sleep

示例:

#include #include 

intmain()

執行結果:

counter=32041

counter=32042

counter=32043

counter=32044

counter=32045

counter=32046

counter=32047

counter=32048

counter=32049

counter=32050

counter=32051

counter=32052

counter=32053

counter=32054

counter=32055

counter=32056

counter=32057

counter=32058

counter=32059

counter=32060

counter=32061

counter=32062

counter=32063

counter=32064

counter=32065

counter=32066

counter=32067

counter=32068alarm clock

可以利用此函式測試cpu效能。

alarm訊號 select RTC定時器

include include void car handler int signo 設定5秒停止錄音 signal sigalrm,car handler alarm 5 設定定時5s原型 intselect int nfds,fd set readfds,fd set writefds,fd s...

linux c之alarm函式的使用,定時器的實現

include include include int main int argc,char argv include include include include include include include include int i it 1 通過呼叫alarm來設定計時器,然後繼續做別的...

用alarm 為recvfrom設定定時器

因為專案需要,需要以5s為週期,收集廣播資訊,所以就要用到定時器和recvfrom函式,而在實用的過程中發現,5s到了,而程式仍然處於阻塞狀態,一直糾結了好久,才找到問題所在,在此mark一下,以備後期回顧。歸根結底,原因在於使用的signal 函式 signal 是重啟函式,超時以後會自動啟動已阻...