#!/bin/sh
kill -9 `ps -ef |grep 进程名 | grep -v grep | awk '{print $2}'`如果还要通过用户名来再次过滤,请使用:
kill $(ps aux | grep 进程名 | grep 用户名 |grep -v grep | awk '{print $2}')参考:https://stackoverflow.com/questions/3510673/find-and-kill-a-process-in-one-line-using-bash-and-regex
有时需要根据用户筛序,而ps命令一般显示的是用户一部分名称+,可以考虑执行ps -o ruser=userForLongName -e -o pid,ppid,c,stime,tty,time,cmd,
ps -o ruser=userForLongName -e -o pid,cmd |grep 用户名|grep 进程名|grep -v grep | awk '{print $2}'参考: