当前位置:网站首页>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:
边栏推荐
猜你喜欢
随机推荐
sublime记录
Beauty Values
People | How did I grow quickly from programmer to architect?
彻底理解工厂模式
focusablejs
基于STM32F103移植FreeRTOS
golang源代码阅读,sync系列-Map
OC-块对象
matlab图像分割,从基因芯片荧光图像中提取阴性点(弱)和阳性点(强)
使用gdb调试多进程程序、同时调试父进程和子进程
b站up主:空狐公子 --矩阵求导(分母布局)课程笔记
electron 应用开发优秀实践
MySQL查询性能优化七种武器之索引潜水
OpenSSF's open source software risk assessment tool: Scorecards
Julia常见符号意思
linux mysql操作的相关命令
End-to-End Object Detection with Fully Convolutional Network学习笔记
1003 Emergency (25分)
程序员的专属浪漫——用3D Engine 5分钟实现烟花绽放效果
c语言函数的递归调用(汉诺塔问题,楼梯递归问题等)