当前位置:网站首页>The use of signal function (signal) in C language
The use of signal function (signal) in C language
2022-08-09 11:16:00 【XV_】
Let's briefly talk about the signal in C language (signal)
First of all, signal is a function in the C language library. It is actually a soft interrupt, which is a terminal issued by the software. In essence, it is similar to int n
.
For the process that receives the soft interrupt signal, it will stop the work at hand and go to execute the signal handler signal handler.
For this, it is similar to hardware interrupts.It's easier to learn by analogy with hardware interrupts!
So what we need to know is
- What soft interrupts are available: like hardware divide by zero interrupt, overflow interrupt, peripheral interrupt...
- What are the soft interrupt handlers: like interrupt service routines (location information is in idt, ivt)
- Default soft interrupt service routine: the default interrupt service routine is initialized when the system starts
- User-defined software interrupt service routine: the operating system can customize the interrupt service routine
And need to understand
- When the interrupt is triggered (trigger condition)
- Who issued the interrupt
- Who received the interrupt
The above are all abstract levels of understanding, we are a thread of the process
- Process x executes
- Process x triggers an interrupt --> issues a soft interrupt
- Process y receives an interrupt, what should process x do
- Process y stops the current task and executes the interrupt service routine instead
- The execution is complete, and the process y continues to execute its own program
As for processes x and y, yes
- Same process
- Two processes
- Parent process and child process
- As for the two independent processes, leave it alone for now. To do this, at least the two must be able to communicate
Okay, the overall framework is sorted out, let's talk slowly.
What are the signals
The reference link above gives all the signals, now we will briefly illustrate them.
Signal | Value | Description |
---|---|---|
SIGCHLD | 17 | Child status has changed (POSIX). Signal sent to parent process whenever one of its child processes terminates or stops. See the YoLinux.com Fork, exec, wait, waitpid tutorial |
SIGCHLD signal: parent process child process
Please see my other article: The use of the semaphore SIGCHLD, how to let the parent process know that the child process executesEnd, how to let the parent process distinguish the end of multiple child processes
Signal handler
Reference:
[1] Signals in C language
[2]How to use signal handlers in C language?
There are two types of signal processing functions
- Processing functions that come with the system
- User-defined function
Similar to the underlying hardware interrupt, the interrupt vector table is built-in, and user-defined is also allowed.
There are also links to default handling of interrupts and custom handling.
Who issued?Who receives it?
- Originator: operating system, or a process
- Receiver: a process
As for the details, it depends on which signal you use.The emitting and receiving actions and objects of each signal, as well as the default handler functions, are specified.
How does it work?
I won't mention this anymore...just a few routines, it's easy.
It should be noted that if process 1 receives signal X from other processes, before process 1 executes the signal x processing function, if multiple signals x are sent to process 1, then these signals may be combined and the process1 executes the signal processing function only once.There could be many reasons for this, such as the operating system being busy...
I have not dealt with the following reference link:
边栏推荐
猜你喜欢
随机推荐
Cesium加载三维模型数据
1005 Spell It Right (20分)
获取指定年度所有周的工具类
Oracle数据库的两种进入方式
富媒体在客服IM消息通信中的秒发实践
x86异常处理与中断机制(2)中断向量表
Invisible OOM in kubernetes
FreeRTOS列表和列表项源码分析
性能测试(03)-JDBC Request
CentOS6.5 32bit安装Oracle、ArcSde、Apache等配置说明
数论知识点
【精华文】C语言结构体特殊情况分析:结构体指针 / 基本数据类型指针,指向其他结构体
在线编译matlab,亲测好用
【C language】typedef的使用:结构体、基本数据类型、数组
二进制加法
c语言函数的递归调用(汉诺塔问题,楼梯递归问题等)
PTA 求一批整数中出现最多的个位数字
STM32启动方式及BootLoader
Missing URI template variable ‘employeeNumber‘ for method parameter of type String
无刷无霍尔BLCD电机控制