1 /** 2 * @file main.c 3 * @author longjin (longjin@RinGoTek.cn) 4 * @brief 测试signal用的程序 5 * @version 0.1 6 * @date 2022-12-06 7 * 8 * @copyright Copyright (c) 2022 9 * 10 */ 11 12 /** 13 * 测试signal的kill命令的方法: 14 * 1.在DragonOS的控制台输入 exec bin/test_signal.elf & 15 * 请注意,一定要输入末尾的 '&',否则进程不会后台运行 16 * 2.然后kill对应的进程的pid (上一条命令执行后,将会输出这样一行:"[1] 生成的pid") 17 * 18 */ 19 20 #include <libc/src/math.h> 21 #include <libc/src/stdio.h> 22 #include <libc/src/stdlib.h> 23 #include <libc/src/time.h> 24 #include <libc/src/unistd.h> 25 26 #include <libc/src/include/signal.h> 27 28 bool handle_ok = false; 29 30 void handler(int sig) 31 { 32 printf("handle %d\n", sig); 33 handle_ok = true; 34 } 35 36 int main() 37 { 38 printf("Test signal running...\n"); 39 signal(SIGKILL, &handler); 40 printf("registered.\n"); 41 42 clock_t last = clock(); 43 while (1) 44 { 45 if ((clock() - last) / CLOCKS_PER_SEC >= 1) 46 { 47 // printf("Test signal running\n"); 48 last = clock(); 49 } 50 if (handle_ok) 51 { 52 printf("Handle OK!\n"); 53 handle_ok = false; 54 } 55 } 56 57 return 0; 58 }