Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- # This script will list all open processes for the given file and give you an option to quit them.
- declare -a PROCS
- s=$(fuser -f "$1")
- PROCS=( $s )
- if [ "${#PROCS[@]}" == 0 ] ; then
- echo "File is not open."
- else
- for element in "${PROCS[@]}"
- do
- ps "$element"
- done
- echo ""
- read -p "Type the PID number to kill a given process, 'a' to kill all or 'q' to quit: "
- if [ "$REPLY" == "a" ] || [ "$REPLY" == "A" ] ; then
- for element in "${PROCS[@]}"
- do
- kill "$element" || exit 1;
- done
- echo "Done"
- elif [ "$REPLY" == "q" ] || [ "$REPLY" == "Q" ]; then
- echo "User cancelled!"
- exit 0;
- else
- kill "$REPLY" || exit 1
- fi
- fi
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement