当前位置:网站首页>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:
边栏推荐
- linux mysql操作的相关命令
- Antdv+Asp.net WebApi开发学生信息管理系统(一)
- Official explanation, detailed explanation and example of torch.cat() function
- 性能测试(04)-表达式和业务关联-JDBC关联
- 二进制加法
- PTA习题 分类统计字符个数(C)
- 程序员的专属浪漫——用3D Engine 5分钟实现烟花绽放效果
- Solve 1. tensorflow runs using CPU but not GPU 2. GPU version number in tensorflow environment 3. Correspondence between tensorflow and cuda and cudnn versions 4. Check cuda and cudnn versions
- Quartz分布式实现
- 【精华文】C语言结构体特殊情况分析:结构体指针 / 基本数据类型指针,指向其他结构体
猜你喜欢

enum in c language

CentOS6.5 32bit安装Oracle-11gR2步骤说明

FreeRTOS列表和列表项源码分析

golang 标准库json Marshal、Unmarshal坑

MySQL传统方案和通过SSH连接哪个好?

Multi-merchant mall system function disassembly 26 lectures - platform-side distribution settings

API接口是什么?API接口常见的安全问题与安全措施有哪些?

prometheus接入mysqld_exporter

People | How did I grow quickly from programmer to architect?

双向链表的各种操作
随机推荐
美的数字化平台 iBUILDING 背后的技术选型
c语言函数的递归调用(汉诺塔问题,楼梯递归问题等)
∘(空心的点乘)的数学含义
【C language】typedef的使用:结构体、基本数据类型、数组
Julia常见符号意思
STM32使用静态队列保存数据
依赖注入(Dependency Injection)框架是如何实现的
多商户商城系统功能拆解26讲-平台端分销设置
无重复字符的最长子串
faster-rcnn learn
linux mysql操作的相关命令
【Subpixel Dense Refinement Network for Skeletonization】CVPR2020论文解读
Looper 原理浅析
x86异常处理与中断机制(1)概述中断的来源和处理方式
MDK添加注释模板
七夕?程序员不存在的~
Official explanation, detailed explanation and example of torch.cat() function
OpenSSF's open source software risk assessment tool: Scorecards
PTA习题 三角形判断
1007 Maximum Subsequence Sum (25分)