在 Linux bash 脚本中杀死 10 分钟前的僵尸进程
我一直在修改 yukondude 收效甚微。我正在尝试终止超过 10 分钟的进程。我已经知道进程 ID 是什么。我每 10 分钟循环一次数组,看看是否有任何挥之不去的进程存在并且需要被杀死。有人对此有什么快速的想法吗?
ps -eo uid,pid,etime 3233332 | egrep ' ([0-9]+-)?([0-9]{2}:?){3}' | awk '{print $2}' | xargs -I{} kill {}
I've been tinkering with a regex answer by yukondude with little success. I'm trying to kill processes that are older than 10 minutes. I already know what the process IDs are. I'm looping over an array every 10 min to see if any lingering procs are around and need to be killed. Anybody have any quick thoughts on this?
ps -eo uid,pid,etime 3233332 | egrep ' ([0-9]+-)?([0-9]{2}:?){3}' | awk '{print $2}' | xargs -I{} kill {}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就像真正的僵尸一样,僵尸进程无法被杀死——它们已经死了。
当它们的父进程调用
wait()
来获取它们的退出代码,或者它们的父进程退出时,它们就会消失。哦,你根本不是在谈论僵尸进程。这个 bash 脚本应该符合您的要求:
这将杀死 UID 1000 拥有的所有运行时间超过 10 分钟(600 秒)的进程。您可能想将其过滤为仅您感兴趣的 PID - 也许通过父进程 ID 或类似的?无论如何,这应该是继续下去的事情。
Just like real Zombies, Zombie processes can't be killed - they're already dead.
They will go away when their parent process calls
wait()
to get their exit code, or when their parent process exits.Oh, you're not really talking about Zombie processes at all. This bash script should be along the lines of what you're after:
That will kill all processes owned by UID 1000 that have been running longer than 10 minutes (600 seconds). You probably want to filter it out to just the PIDs you're interested in - perhaps by parent process ID or similar? Anyway, that should be something to go on.