In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today Xiaobian to share with you the linux process signal communication instance analysis related knowledge points, detailed content, clear logic, I believe most people are still too familiar with this knowledge, so share this article for everyone to refer to, I hope you read this article after some harvest, let's take a look at it.
In iTOP4412 development board running, when we encounter a software on win that cannot be closed properly, we can open the task manager and force the process to end. Similarly. Similar functionality exists on linux, such as typing ctrl+c from the terminal to generate a signal that a running process will react to when it catches.
We can use the shortcut keys to enter the task manager on win, so in what cases will the signal be generated in linux?
So how many kinds of signals does linux have? We can check it by commanding kill command.
We can see that there are 64 kinds of signals, each of which starts with sig, and the name of the signal is defined in signal.h.
Part 1: Transmission of signals
Let's take a small example of how signals are sent:
This program mainly uses the kill function, because user space is not capable of sending signals, only the kernel can send signals, the kernel has so many signals, which signal do we want to send, and who to send it? Then we need to tell the kernel process PID, signal ID is what, kill function to help us solve this problem, function prototype:
Compile and run:
From the function prototypes of kill and raise, raise has no pid parameter, so raise can be implemented by kill. Equivalent to:
Part I Signal Transmission Summary:
User space can not send signals, is through the system call function to tell the kernel what signals, to whom, let the kernel to send, only the kernel can send signals. You can use the kill, raise, alarm function to get the kernel to send signals.
Second part signal reception
We can use pause to receive signals, and the pause function causes the process to pause to yield CPU. Let's look at the following example. When we press ctrl+c on the keyboard, the program will wake up when it receives the SIGINT signal, and then execute the fun function. After processing, it will return to continue running the program. If it does not press, it will only print process start(enter sleep state).
Part III Signal Processing
There are three ways to process signals: 1, ignore, that is, after receiving the signal, do nothing, do not process. 2, according to the default way to deal with. 3, capture and process, capture the signal, execute the code we want to execute. Let's look at the signal function:
Compile and run, because we use SIG_IGN, so we press ctrl+c without interrupting the program.
Compile and run, and when we press ctrl+c, it interrupts our program.
When we press ctrl+c, we go to fun.
2, user space can not send signals, the signal generation from the kernel, let the kernel generate signals in the way: through the keyboard input ctrl+c and so on. When a program runs incorrectly, the kernel sends a signal to the process, such as floating point overflow, and a program can signal another process by calling a function, such as kill.
3. After the process receives the signal, it can ignore it, or process it according to the default mode, or process it according to its own processing function. Signale is permanently registered and valid every time. If you don't want to, you can use sigaction.
The above is "linux process signal communication example analysis" all the contents of this article, thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.