关闭进程的简单shell

mac上的eclipse经常需要手动的去关闭java进程,略麻烦。在.bash_profile里写了段简单的shell,用端口号关闭进程,主要用的是lsof -ti:9001.之后$source .bash_Profile即可使用killps命令。 

killprocess() {
pid=`lsof -n -i4TCP:9001 | grep LISTEN | awk '{print $2}'`
if [ $pid ]
    then
        kill -9 $pid
        echo "pid=$pid, kill successfull!"
else
    echo "No process exists on port $1."
fi
}
alias killps=killprocess

截图如下:

killps

原文地址:https://www.cnblogs.com/timelyxyz/p/2889307.html