how to detect Linux shutdown/reboot

前端 未结 2 1581
余生分开走
余生分开走 2020-12-17 23:44

I\'m trying to detect shut down or reboot from Linux in my c program. I found that program can use signal(SIGTERM, handler) (SIGKILL, handler). But these two will trigger if

2条回答
  •  臣服心动
    2020-12-18 00:29

    Catch SIGTERM. In the handler, read the /var/run/utmp file to get the runlevel. See the source code of the runlevel(8) command for reference.

提交回复
热议问题