關於 timer signal - Linux

Table of Contents

版友好

我寫了一個小程式,這程式會打開 /dev/hidraw0 這個節點

一打開成功後,就會啟動一個 一秒之後會執行別的程式的 timer

signal(SIGALRM, calculate_crc_per_sec);
alarm(1);

接著馬上進入 while 迴圈對 hidraw0 作讀取

while 裡面有對一些全域變數作運算

calculate_crc_per_sec 裡面就印出這些全域變數,也會assign值,然後再設定alarm(1)

。也就是每一秒都會觸發這個timer。

我知道這可能會牽涉到 calculate_crc_per_sec 內作運算值,結束後,while也會對變數

做處理會導致值不太對。


但我每次都會遇到系統鎖死重開機的狀況阿....? 請問這是啥原因



謝謝。



--

All Comments

Vanessa avatarVanessa2017-03-09
你是用printf印出變數內容? printf不是signal safe
Catherine avatarCatherine2017-03-09
我是在安卓上開發,印出是用ALOGD(),何謂non-safe?