mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-23 08:03:22 +00:00
29
user/apps/test_sigint/main.c
Normal file
29
user/apps/test_sigint/main.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// 信号处理函数
|
||||
void handle_signal(int signal)
|
||||
{
|
||||
if (signal == SIGINT)
|
||||
{
|
||||
printf("Caught SIGINT (Ctrl+C). Exiting gracefully...\n");
|
||||
exit(0); // 终止程序
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// 注册信号处理函数
|
||||
signal(SIGINT, handle_signal);
|
||||
|
||||
// 模拟一个长时间运行的进程
|
||||
while (1)
|
||||
{
|
||||
printf("Running... Press Ctrl+C to stop.\n");
|
||||
sleep(5);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user