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
MySQL is a relational database management system ...
1. Install nginx in docker: It is very simple to ...
Discovering Needs If only part of an area is allo...
By default, PHP on CentOS 7 runs as apache or nob...
Table of contents Problem Description Solution Pr...
Docker Installation There is no need to talk abou...
1. Differences between JSON.stringify() and JSON....
In web development, you often encounter characters...
Preface: When you execute a SQL statement in MySQ...
Preface Nginx (pronounced "engine X") i...
MySQL is a very powerful relational database. How...
Recently, students from the User Experience Team o...
Refer to the tutorial on setting up FTP server in...
Some tips for deep optimization to improve websit...
Preface The basic principle of MySQL master-slave...