How to kill all processes matching a name?

后端 未结 11 1514
不思量自难忘°
不思量自难忘° 2020-11-29 14:53

Say I want to kill every process containing the word amarok. I can print out the commands I want to execute. But how do I actually make the shell execute them. ie.



        
相关标签:
11条回答
  • 2020-11-29 15:15

    I think this command killall is exactly what you need. The command is described as "kill processes by name".It's easy to use.For example

    killall chrome
    

    This command will kill all process of Chrome.Here is a link about killall command

    http://linux.about.com/library/cmd/blcmdl1_killall.htm

    Hope this command could help you.

    0 讨论(0)
  • 2020-11-29 15:16

    try kill -s 9 ps -ef |grep "Nov 11" |grep -v grep | awk '{print $2}' To kill processes of November 11 or kill -s 9 ps -ef |grep amarok|grep -v grep | awk '{print $2}' To kill processes that contain the word amarok

    0 讨论(0)
  • 2020-11-29 15:18
    ps aux | grep -ie amarok | awk '{print $2}' | xargs kill -9 
    

    xargs(1): xargs -- construct argument list(s) and execute utility. Helpful when you want to pipe in arguments to something like kill or ls or so on.

    0 讨论(0)
  • 2020-11-29 15:18

    You can also evaluate your output as a sub-process, by surrounding everything with back ticks or with putting it inside $():

    `ps aux | grep -ie amarok | awk '{print "kill -9 " $2}'`
    
     $(ps aux | grep -ie amarok | awk '{print "kill -9 " $2}')     
    
    0 讨论(0)
  • 2020-11-29 15:19

    If you want to execute the output of a command, you can put it inside $(...), however for your specific task take a look at the killall and pkill commands.

    0 讨论(0)
提交回复
热议问题