[C.C++] 写一个简单的中断门程序

1366 0
狼毛 2023-8-25 20:19:39 | 显示全部楼层 |阅读模式
  1. //写一个简单的中断门程序
  2. #include <stdio.h>
  3. #include <signal.h>
  4. #include <unistd.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <errno.h>
  8. #include <sys/types.h>



  9. void sig_handler(int signo)
  10. {
  11.     printf("recv a signal:%d\n",signo);
  12.     sleep(5);
  13.     printf("after sleep\n");
  14.     return;
  15. }

  16. int main()
  17. {
  18.     signal(SIGINT,sig_handler);
  19.     while(1)
  20.     {
  21.         printf("hello\n");
  22.         sleep(1);
  23.         printf("world\n");
  24.         sleep(1);
  25.         printf("end\n");
  26.         sleep(1);
  27.     }
  28.     return 0;
  29. }




复制代码



您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

狼毛

精英红客

关注
  • 206
    主题
  • 2
    粉丝
  • 1
    关注
这家伙很懒,什么都没留下!

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行