《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
542 B

  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <signal.h>
  5. // Define the function to be called when ctrl-c (SIGINT) signal is sent to process
  6. void
  7. signal_callback_handler(int signum)
  8. {
  9. printf("Caught signal %d\n",signum);
  10. // Cleanup and close up stuff here
  11. // Terminate program
  12. exit(signum);
  13. }
  14. int main()
  15. {
  16. // Register signal and signal handler
  17. signal(SIGINT, signal_callback_handler);
  18. while(1)
  19. {
  20. printf("Program processing stuff here.\n");
  21. sleep(1);
  22. }
  23. return EXIT_SUCCESS;
  24. }