systemd stop 命令的实际工作原理

编程入门 行业动态 更新时间:2024-10-24 22:23:59
本文介绍了systemd stop 命令的实际工作原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在使用 systemd 服务,该服务在启动"进程时调用该进程(例如 $systemctl start test.service).根据设计,进程永远处于循环中,我们可以使用ps"命令查看进程存在.我们还看到该进程被 systemctl stop 命令杀死(如预期).但是我们的要求是,我们希望在进程被杀死之前从进程内部执行一些安全的关闭操作.但我不确定如何从进程中检测 systemd 停止操作.

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, we are able to see process existence using 'ps' command. We have also seen that the process is getting killed (as intended) for systemctl stop command. However our requirement is, we want to do some safe shutdown operations from within the process before it gets killed. But I am not sure how to detect a systemd stop operation from within the process.

systemctl stop test.service 命令是否发送 SIGKILL 或 SIGTERM 信号来终止进程?如何从进程中检测 systemctl stop 操作?

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?

推荐答案

默认情况下,发送 SIGTERM,然后等待 90 秒,然后是 SIGKILL.

By default, a SIGTERM is sent, followed by 90 seconds of waiting followed by a SIGKILL.

使用 systemd 杀死进程是非常可定制的并且文档齐全.

Killing processes with systemd is very customizable and well-documented.

我建议阅读所有 man systemd.kill 作为以及阅读ExecStop= in man systemd.service.

I recommend reading all of man systemd.kill as well as reading about ExecStop= in man systemd.service.

要响应这些信号,请参阅您所使用语言的信号处理文档.

To respond to those signals, refer to the signal handling documentation for the language you are using.

这篇关于systemd stop 命令的实际工作原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 12:10:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1409419.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工作原理   命令   systemd   stop

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!