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

标签 linux bash shell kill-process working-directory

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

相关文章:

linux - 运行 Perl 脚本时意外锁定了文件夹

c - shell如何扩展*.c?

shell - 与命名管道分离而不终止源程序

linux - 在转储到文件之前处理从 bash 脚本中的 find 命令获取的字符串

java - Runtime.getRuntime().exec 奇怪的行为

linux - 在 Azure HdInsight 的 Linux 群集上的 Spark 中运行 Zeppelin 段落时出错

linux - 从 tasklet 中 wake_up_interruptible() 是否安全?

linux - 使用 sed "s| ACT: ||"

bash - 当进程不存在时管道到进程?

linux - gdb -x 共享库断点