如果一个进程被 sigkill 杀死,我如何让它再次运行?

发布于 2024-09-02 06:04:09 字数 47 浏览 8 评论 0原文

我有一个其他进程试图杀死的进程,如果他们设法杀死它,我如何确保该进程将再次运行?

I have a process that other processes are trying to kill and if they manage to do it, how can I make sure the process will run again?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

长不大的小祸害 2024-09-09 06:04:09

查看 inittab。寻找重生:)

该进程将重新启动
每当它终止时

我自己的 inittab 中的一个示例:

c1:2345:respawn:/sbin/agetty -8 38400 tty1 linux

c1 是一个 id(has 是唯一的),2,3,4,5 code> 是适用的运行级别,respawn 说明了我之前所说的内容,其余的是命令。在那里你可以简单地添加你的命令,它应该可以正常工作。

Check out inittab. Look for respawn :)

The process will be restarted
whenever it terminates

Here is an example from my own inittab:

c1:2345:respawn:/sbin/agetty -8 38400 tty1 linux

c1 is an id (is has to be unique), 2,3,4,5 are the runlevels to which this applies, respawn states what I have said earlier and the rest is a command. There you can simply add your command and it should work well.

记忆里有你的影子 2024-09-09 06:04:09

您可以从 inittab 重生,但您几乎无法控制何时以及如何重新启动进程 - 您必须编辑 inittab 才能停止重生。此外,inittab 重生无法对锁定的进程和消耗大量 CPU 或 RAM 资源的疯狂进程执行任何操作。您也不会注意到您的进程每两秒重新启动一次。

您可以使用进程监控守护程序来获得额外的功能和灵活性。监控守护进程允许您向过程控制添加任意复杂的行为。当然,如果您的要求太过分,您可能最终不得不编写自己的守护程序。

最好使用满足您需求的现有解决方案。

我使用 Monit 取得了良好的效果。配置语言非常强大,如果需要,您可以做相当复杂的事情。您还可以启用 Web 界面,允许您远程停止、启动和禁用进程。查看演示文稿了解概述。

You can respawn from inittab, but you have little control of when and how the process should be restarted--you have to edit the inittab to stop respawning. Also, inittab respawning can't do anything about locked processes and processes gone wild that are consuming massive CPU or RAM resources. You will also have no notice that your process is restarting every two seconds.

You can use a process monitoring daemon to get extra capabilities and flexibility. Monitoring daemons allow you to add arbitrarily complex behaviors to your process control. Of course, if you go too far in your demands, you may wind up having to write your own daemon.

It's better to use an existing solution that meets your needs.

I have had good results with Monit. The configuration language is quite powerful and you can do fairly complex things if you need to. You can also enable a web interface that allows you to stop, start and disable processes remotely. Check out the presentation for an overview.

笑咖 2024-09-09 06:04:09

信号之间的信号处理有所不同。大多数信号到达目标进程,信号处理程序可以在其中处理它,例如 SIGTERM,这是 kill 通常发送的信号。如果使用kill -sigkill(或kill -9,它们是等效的),则信号永远不会到达进程;进程会以对操作系统安全的方式尽快被杀死(如果它正忙于系统调用,则系统调用完成后它将被杀死,就像杀死内核中运行的线程一样)如果未释放锁等,模式可能会破坏操作系统。

因此,无论编程语言如何,进程都无法阻止 SIGKILL 或从 SIGKILL 中恢复。

Signal handling differs between the signals. Most signals reach the target process where a signal handler can take care of it e.g. SIGTERM which is what kill normally sends. If kill -sigkill (or kill -9, they are equivalent) is used the signal never reaches the process; the process is killed as soon as it can in a way that is safe for the OS (if it is busy in a system call, it will be killed as soon as the system call is finished, as a kill of a thread running in kernel mode could possibly chrash the OS if locks are not released etc).

So there is no way at all for a process to block or recover from a SIGKILL, regardless of programming language.

倦话 2024-09-09 06:04:09

某些 Linux 版本(如 Ubuntu)更喜欢 /etc/event.d 而不是 inittab。这是一个类似的概念,但不同的实现。

Some Linux versions (like Ubuntu) prefer /etc/event.d instead of inittab. It's a similar concept, but different implementation.

人生戏 2024-09-09 06:04:09

你总是可以拉一个罗宾汉/塔克修士

You could always pull a Robin Hood/Friar Tuck thing, but these days you can kill both processes at the same time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文