Chinaunix

标题: 关于信号捕获的问题 [打印本页]

作者: CrossGrave    时间: 2016-01-04 15:50
标题: 关于信号捕获的问题
写了一个程序,现在可以正常捕获kill信号  SIGTERM   但是无法对poweroff和reboot捕获, 我网上查询了一下 说 poweroff和reboot后会先给程序发送SIGTERM然后再给程序发送SIGKILL 这两个信号,前者可以被捕获 后者不能。但是我在系统中使用reboot和poweroff都是无法捕获到SIGTERM信号的。程序可以正常捕获到kill命令发出来的信号。 系统是centos7 。求大神解惑,告知原理,谢谢。
作者: happy_fish100    时间: 2016-01-04 16:26
mac OS下的reboot命令manual:
The halt and reboot utilities flush the file system cache to disk, send all running processes a SIGTERM (and subsequently a SIGKILL) and, respectively, halt or restart the system.

而linux下的manual没有提到这样的字样。
对于linux,可以做成service,系统reboot或者halt时,应该会调用service的stop方法(这点有待确认)。





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2