linux 信號簡單例子分析

#include #include #include #include void ouch(int sig) { printf("OUCH! I got signal %d/n", sig); (void)signal(SIGINT, SIG_DFL);//ouch處理了第一個ctrl+c信號之後,交給默認的SIG_DFL處理,即中斷程序 } int main() { (void)signal(SIGINT, ouch);//首先等待ctrl+c信號並交給ouch方法處理 while(1) { printf("Hello, World! Signal Test Here!! /n"); sleep(1); } } 另外要記住永遠調用信號的名字而不是直
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章