如何杀死外壳的子进程? [英] How to kill all subprocesses of shell?

查看:136
本文介绍了如何杀死外壳的子进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写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来这里找到并杀死所有的孙子等过程的描述或<一个href=\"http://www.unix.com/unix-dummies-questions-answers/5245-script-kill-all-child-process-given-pid.html\">here.

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

这篇关于如何杀死外壳的子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆