脚本宝典收集整理的这篇文章主要介绍了php – 如何捕获KILL或HUP或用户中止信号?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我认为我需要捕获的大部分内容是SIginT,SIGTERM,SIGHUP,SIGKILL.
如何捕获这些信号并使其执行退出功能,否则继续执行它正在执行的任何操作?
#!/usr/bin/perl use stricts; use warnings; while (true) { #my happy code is running #my happy code will sleep for a few until ITs breath is back to keep running. } #ops I have detected an evil force trying to kill me #let's call the safe exit. sub safe_exit() { # save stuff exit(1); }
<?PHP while (1) { #my happy code is running #my happy code will sleep for a few until its breath is back to keep running. } #ops I have detected an evil force trying to kill me #let's call the safe exit. function safe_exit() { # save stuff exit(1); } ?>
pcntl_signal
来注册信号处理程序,所以像这样:
declare(ticks = 1); function sig_handler($sig) { switch($sig) { case SIGINT: # one branch for signal... } } pcntl_signal(SIGINT,"sig_handler"); pcntl_signal(SIGTERM,"sig_handler"); pcntl_signal(SIGHUP,"sig_handler"); # Nothing for SIGKILL as it won't work and trying to will give you a warning.
以上是脚本宝典为你收集整理的php – 如何捕获KILL或HUP或用户中止信号?全部内容,希望文章能够帮你解决php – 如何捕获KILL或HUP或用户中止信号?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。