rudimentary kill script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Here is a quick way to kill all processes that might have an open file on some volume you want to umount and close.

kill_all_dm() {
hexdev=$(dmsetup info -c -o major,minor $1 --noheadings | tr ':' ' ' | { read a b; printf "D0x%02x%02x\n" $a $b; }) process_list=$(lsof -F cDn0 | tr '\0' '\t' | awk -F '\t' '{ if (substr($1,1,1) == "p") P=$1; else print P "\t" $0 }' | grep $hexdev | awk '{print $1}' | sed "s/^p//")
    [ -n "$process_list" ] && echo "$process_list" | xargs kill -9
}

It works on logical volumes and device mapper (paths) equally, but you must specify the path:

kill_all_dm /dev/linux/root ;-).



Alternatively this will just list all open processes:

find_processes() {
hexdev=$(dmsetup info -c -o major,minor $1 --noheadings | tr ':' ' ' | { read a b; printf "D0x%02x%02x\n" $a $b; }) process_list=$(lsof -F cDn0 | tr '\0' '\t' | awk -F '\t' '{ if (substr($1,1,1) == "p") P=$1; else print P "\t" $0 }' | grep $hexdev | awk '{print $1}' | sed "s/^p//")
    [ -n "$process_list" ] && echo "$process_list" | xargs ps
}

find_processes /dev/linux/root

_______________________________________________
linux-lvm mailing list
linux-lvm@redhat.com
https://www.redhat.com/mailman/listinfo/linux-lvm
read the LVM HOW-TO at http://tldp.org/HOWTO/LVM-HOWTO/



[Index of Archives]     [Gluster Users]     [Kernel Development]     [Linux Clusters]     [Device Mapper]     [Security]     [Bugtraq]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]

  Powered by Linux