Is there a way to kill all processes running in / from a specific directory?

I need a way to kill everything that works in the current directory. I'm a little new to shells, so forgive me for being stupid or potentially not understanding your answers. I have a half-grabbing grab, but if you please take extra time to explain what exactly your solution makes for my problem, it would be very helpful.

+4
source share
1 answer

you need to use the command lsof, then the argument will be the directory you want to kill.

#!/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
0
source

Source: https://habr.com/ru/post/1686919/


All Articles