如何杀死外壳的子进程?

编程入门 行业动态 更新时间:2024-10-28 09:26:41
本文介绍了如何杀死外壳的子进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我写bash脚本,这确实几个事情。

I'm writing bash script, which does several thing.

在它开始的几个监控脚本开始,他们每个人运行一些其他的工具。

In the beginning it starts several monitor scripts, each of them runs some other tools.

目前我的主要脚本结束,我想干掉,从我的shell产生的所有的东西。

At the end of my main script, I would like to kill all things that spawned from my shell.

因此​​,它可能是这样的:

So, it might looks like this:

#!/bin/bash some_monitor1.sh & some_monitor2.sh & some_monitor3.sh & do_some_work ... kill_subprocesses

问题是,大多数显示器酿出自己的子流程,这样做(例如): killall some_monitor1.sh 不会总是帮助

任何其他方式来处理这种情况?

Any other way to handle this situation?

推荐答案

开始每个子进程后,就可以得到它的ID以

After starting each child process, you can get its id with

ID=$!

然后你可以使用存储的PID来这里找到并杀死所有的孙子等过程的描述或here.

Then you can use the stored PIDs to find and kill all grandchild etc. processes as described here or here.

更多推荐

如何杀死外壳的子进程?

本文发布于:2023-10-06 17:56:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467612.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:外壳   进程

发布评论

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

>www.elefans.com

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