How systemd stop command actually works

后端 未结 2 872
不知归路
不知归路 2020-12-23 15:53

I am using a systemd service which calls a process when it\'s been \"started\" (e.g.$systemctl start test.service). As per the design, the process stays for ever in a loop,

2条回答
  •  既然无缘
    2020-12-23 16:43

    Does a systemctl stop test.service command send SIGKILL or SIGTERM signal to kill the process? How can i detect a systemctl stop operation from within a process?

    Systemd sends SIGTERM signal to process. In process you have to register signals, which are "catched".

    In process, eg. SIGTERM signal can be registered like this:

    void signal_callback()
    {
        printf("Process is going down\n");
    }
    signal(SIGTERM, signal_callback)
    

    When SIGTERM is sent to process signal_callback() function is executed.

提交回复
热议问题