允许用户自定义信号处理函数 (#112)

* new: 用户注册信号处理函数,能够进入自定义的handler

* 修复忘了传信号的数字给用户的处理函数的bug

* new:sigreturn

* 删除注释
This commit is contained in:
login
2022-12-17 16:27:50 +08:00
committed by GitHub
parent 0e0c187484
commit 6efd474033
12 changed files with 566 additions and 100 deletions

View File

@ -1,12 +1,12 @@
/**
* @file main.c
* @file main.c
* @author longjin (longjin@RinGoTek.cn)
* @brief 测试signal用的程序
* @version 0.1
* @date 2022-12-06
*
*
* @copyright Copyright (c) 2022
*
*
*/
/**
@ -14,8 +14,8 @@
* 1.在DragonOS的控制台输入 exec bin/test_signal.elf &
* 请注意,一定要输入末尾的 '&',否则进程不会后台运行
* 2.然后kill对应的进程的pid (上一条命令执行后,将会输出这样一行:"[1] 生成的pid")
*
*/
*
*/
#include <libc/src/math.h>
#include <libc/src/stdio.h>
@ -23,16 +23,36 @@
#include <libc/src/time.h>
#include <libc/src/unistd.h>
#include <libc/src/include/signal.h>
bool handle_ok = false;
void handler(int sig)
{
printf("handle %d\n", sig);
handle_ok = true;
}
int main()
{
printf("Test signal running...\n");
signal(SIGKILL, &handler);
printf("registered.\n");
clock_t last = clock();
while (1)
{
if ((clock()-last)/CLOCKS_PER_SEC >= 1){
if ((clock() - last) / CLOCKS_PER_SEC >= 1)
{
// printf("Test signal running\n");
last = clock();
}
if (handle_ok)
{
printf("Handle OK!\n");
handle_ok = false;
}
}
return 0;
}