gpt4 book ai didi

linux - 有没有办法杀死在某个目录中/从某个目录运行的所有进程?

转载 作者:IT王子 更新时间:2023-10-29 00:43:32 24 4
gpt4 key购买 nike

我需要一种方法来杀死当前目录中正在运行的所有内容。我对 shell 有点陌生,所以请原谅我的愚蠢或可能不理解您的回答。我有一半的把握,但如果你愿意花额外的时间来解释你对我的问题的解决方案到底做了什么,我将不胜感激。

最佳答案

你必须使用lsof命令然后参数将是你想要终止进程的目录

#!/usr/bin/env bash                                                                                                                                 
lsof $(pwd) | \
awk -F " " ' { print $2 } ' | \
while read process ; do
[[ ${process} == "PID" ]] && continue;
# kill the processes here
# if you assign each process to a variable or an array
# you will not be able to access it after leaving this while loop
# pipes are executed as subshells
echo ${process};
done

关于linux - 有没有办法杀死在某个目录中/从某个目录运行的所有进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46576125/

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