How to detect pending system shutdown on Linux?

前端 未结 9 1063
死守一世寂寞
死守一世寂寞 2020-12-05 14:37

I am working on an application where I need to detect a system shutdown. However, I have not found any reliable way get a notification on this event.

I know that o

9条回答
  •  隐瞒了意图╮
    2020-12-05 15:10

    There is no way to determine if a SIGTERM is a part of a shutdown sequence. To detect a shutdown sequence you can either use use rc.d scripts like ereOn and Eric Sepanson suggested or use mechanisms like DBus.

    However, from a design point of view it makes no sense to ignore SIGTERM even if it is not part of a shutdown. SIGTERM's primary purpose is to politely ask apps to exit cleanly and it is not likely that someone with enough privileges will issue a SIGTERM if he/she does not want the app to exit.

提交回复
热议问题