在Linux系统上,信号-KILLTERM发送一个允许应用程序安全关闭的信号。这些问题可能有点理论性,但我想要理解它们。
这些问题来自于Linux看门狗,在阅读手册页时,我看到监督狗的过程是首先向给定的PID发送终止信号,然后发送杀死-9信号来强制它。我想要能够利用内建的安全监督狗。
发布于 2015-11-03 15:44:43
看这段代码
#include<stdio.h>
#include<signal.h>
#include<stdlib.h>
void cleanUp(){ // Do whatever you want here
printf("Safely terminating \n");
}
void hand(int sig){ // called when you are sent SIGTERM
/*
Here you can safely terminate..
*/
atexit(cleanUp); // call cleanUp at exit.
exit(0);
}
int main(){
signal(SIGTERM, hand); //Assign function to be called on SIGTERM
/*
Your code goes here.
I have put an infinite loop for demonstration.
*/
printf("Started execution..\n");
for(;;);
}这显示了在向应用程序传递信号时如何分配调用函数。
若要将信号SIGTERM传递到此代码,请执行以下操作,
kill -SIGTERM <pid>在这里,<pid>标识正在运行的程序的进程id。
https://stackoverflow.com/questions/33502525
复制相似问题