Introduction to Linux alarm function Above code: #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <signal.h> int main(int argc, char *argv[]) { alarm(5); sleep(20); printf("end!\n"); return 0; } After running for 5 seconds, the kernel sends a
Of course, we can also manually define the signal processing function as follows: #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <signal.h> void sig_alarm(int sig) { printf("sig is %d, sig_alarm is called\n", sig); } int main(int argc, char *argv[]) { signal(SIGALRM, sig_alarm); // Register the function corresponding to the alarm signal alarm(5); // After 5 seconds, the kernel sends an alarm signal to the process and executes the corresponding signal registration function sleep(20); printf("end!\n"); return 0; } result:
It can be seen that the kernel sends a SIGALRM signal to the application process and executes the corresponding registration function instead of killing the process. It’s very simple, that’s all I have to say for now. Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links You may also be interested in:
|
<<: Configuring MySQL and Squel Pro on Mac
>>: vue.config.js packaging optimization configuration
This article shares the specific code for impleme...
Here are a few ways to remove it: Add the link dir...
The methods and concepts of private filters and g...
Table of contents 1. Introduction to sysbench #Pr...
Usually a CSS selector selects from top to bottom...
The installation tutorial of MySQL 5.7.27 is reco...
Table of contents 1. Log related services 2. Comm...
1. Prerequisites Since I have installed it severa...
Table of contents Preface Configure yum source, e...
1. Check the character set of the database The ch...
Query mysql operation information show status -- ...
This article example shares the specific code of ...
This is an important (and wonderful) topic for Li...
1. After entering the container cat /etc/hosts It...
Today I saw a blog post about input events, and o...