gpt4 book ai didi

linux - 如何找出进程何时在 Linux 中退出?

转载 作者:IT王子 更新时间:2023-10-29 00:20:15 26 4
gpt4 key购买 nike

在 Linux 中,我找不到确定进程何时退出的好方法。有人对此有解决方案吗?

我能想到的一个方法是定期检查进程列表,但这不是即时的而且非常昂贵(每次都必须遍历所有进程)。

在 Linux 上是否有用于执行此操作的界面?像 waitpid 这样的东西,除了可以从不相关的进程中使用的东西?

谢谢,博达赛多

最佳答案

你不能等待一个不相关的过程,只是 child 。

比检查进程列表更简单的轮询方法,如果你有权限,你可以使用kill(2)系统调用和“发送”信号0。

来自 kill(2) 手册页:

If sig is 0, then no signal is sent, but error checking is still performed; this can be used to check for the existence of a process ID or process group ID

关于linux - 如何找出进程何时在 Linux 中退出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3676686/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com