我需要一种方法来杀死当前目录中正在运行的所有内容。我对 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/