# Linux通过进程名来杀死进程
#!/bin/sh
kill -9 `ps -ef |grep 进程名 | grep -v grep | awk '{print $2}'`
参考:https://blog.csdn.net/qq_38486203/article/details/113634142 (opens new window)
如果还要通过用户名来再次过滤,请使用:
kill $(ps aux | grep 进程名 | grep 用户名 |grep -v grep | awk '{print $2}')
有时需要根据用户筛序,而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}'
参考:
https://blog.csdn.net/qq_15682815/article/details/87921482 (opens new window)