Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

kill and pid files



	I find myself using "kill -HUP $(cat /var/run/<program>.pid)"
constantly... in fact, as root I use that line much more often than using
a literal pid.
	Is there any reason kill should not take a filename as an
argument?  i.e. if the job specification is not a legal job name, or a
legal pid, why not try to open a file with that name and see if it's
first line is a valid pid?

	Here's the idea, but this thing is horribly slow at times.

function mykill {
    args=()
    if ! kill "$argv[@]" 2> /dev/null
    then while [ "$argv" ]
        do case "$argv[1]"
            in
              -s)
                args=("$args[@]" "$argv[1]" "$argv[2]")
                shift 2
                ;;
              -l)
                args=("$args[@]" "$@")
                shift "$#"
                ;;
              -*)
                args=("$args[@]" "$argv[1]")
                shift
                ;;
              *)
                if echo "$argv[1]" | egrep -q '^%[0-9]+$'
                then args=("$args[@]" "$argv[1]")
                    shift
                elif echo "$argv[1]" | egrep -q '^[0-9]+$'
                then args=("$args[@]" "$argv[1]")
                    shift
                elif [ -f "$argv[1]" ] &&
                    head -1 "$argv[1]" | egrep -q '^[0-9]+$'
                then args=("$args[@]" "$(head -1 "$argv[1]")")
                    shift
                else args=("$args[@]" "$argv[1]")
                    shift
                fi
                ;;
            esac
        done
        kill "$args[@]"
    fi
}




Messages sorted by: Reverse Date, Date, Thread, Author