mirror of
https://github.com/XMuli/QtExamples.git
synced 2026-10-29 04:16:50 +08:00
- 自定义信号集: - sigaddset() //将指定信号置为 1,添加到自定义集中 - sigdelset() //将指定信号置为 0,添加到自定义集中 - sigemptyset() //将所有信号置为 0,清空 - sigfillset() //将所有信号置为 1,填充 - sigismember() //判断指定信号是否存在,是否为 1 - 系统信号集: - sigprocmask() //将自定义信号集设置给阻塞信号集。 - sigprocmask() //读取当前信号的未决信号集。参数为输出参数,内核将未决信号集写入 set - 信号捕捉: - signal() //实现信号捕捉的功能;最简单使用一个函数。 - sigaction() //同上,多一个额外功能,运行期间能够**临时** 屏蔽指定信号
24 lines
473 B
C++
24 lines
473 B
C++
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <sys/wait.h>
|
|
#include <sys/time.h>
|
|
#include <signal.h>
|
|
|
|
void func(int no); //用作回调函数,给 signal() 调用
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
signal(SIGINT, func); //设置信号捕捉函数, 捕捉 ctrl + c
|
|
|
|
while (true) {
|
|
printf("Keep the thread running for the non-death state.\n");
|
|
sleep(1);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void func(int no)
|
|
{
|
|
printf("捕捉的信号为: %d\n", no);
|
|
} |