ulysses 寫:
碰到不清楚的函式,記得要先去問男人喔。

啊?不懂??是指問女人會【問道於盲】嗎?
原來【The ualarm() function appeared in 4.3BSD.】這是 BSD 的函式啊,Windows 不支援這個吧?
所以你說的【Standard C Library 的一個函式】指的應該是 UNIX/Linux 系統,而不是 Windows 吧?我手上的書沒找到....
我找到這個:
http://www.osxfaq.com/man/3/ualarm.ws
include <unistd.h>
u_int
ualarm(u_int microseconds, u_int interval)
看了半天我只知道這個 ualarm() 需要兩個從 0 開始的正整數,第二個參數若不是 0 會每隔幾個微秒重複一次。
底下的東西對我來說是.... 有字天書,看不懂~~~
不幸的是,你早就懂了...... 淚~~ 我老了...... 泣~~~
http://www.linux.or.jp/JM/html/LDP_man-pages/man3/ualarm.3.html
/* BSD 版 */
#include <unistd.h>
unsigned int
ualarm(unsigned int usecs, unsigned int interval);
/* SUSv2 版 */
#define _XOPEN_SOURCE 500
#include <unistd.h>
useconds_t ualarm(useconds_t usecs, useconds_t interval);
The ualarm() function waits a count of microseconds before asserting the
terminating signal SIGALRM. System activity or time used in processing
the call may cause a slight delay.
If the interval argument is non-zero, the SIGALRM signal will be sent to
the process every interval microseconds after the timer expires (e.g. af-
ter value microseconds have passed).
實時間隔定時器有點特別。 Linux 在核心中使用了定時器機制來處理它。 每個程序有
自己的 timer_list 資料結構, 當實時間隔定時器運行時, 系統的 timer list (定時器列表)中把
它排入了隊列。 當定時器的時間間隔一到, 負責處理定時器事件的 bottom half handler 會
把它從隊列中刪除, 然後調用調用間隔定時器的處理器(並不是 CPU, 而是一段程式碼)。 這
個處理器這就產生了 SIGALRM 信號並且重啟間隔定時器, 又把它加入系統定時器隊列。