1
$ ps aux | grep ruby user 1565 3.7 0.1 4307464 17696 s000 S+ 7:31AM 0:00.61 /Users/user/.rbenv/versions/2.3.1/bin/ruby bin/rails c user 1579 0.0 0.0 4268020 788 s001 S+ 7:31AM 0:00.00 grep ruby user 1489 0.0 0.0 0 0 ?? Z 7:29AM 0:00.00 (ruby) 

How do I quickly kill all these processes?

What I tried:

kill -9 `ps aux | grep ruby` 

My environment:

$ bash --version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18) Copyright (C) 2007 Free Software Foundation, Inc. $ uname -a Darwin MacBook-Pro.local 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64 $ 
1
  • 1
    pkill might be the command you're looking for. Commented Nov 20, 2018 at 15:42

3 Answers 3

3

As Haxiel commented, my recommendation would be to use pkill:

pkill -9 ruby 
5
  • -9 is it required? Commented Nov 20, 2018 at 18:09
  • 1
    Nope; the OP gave that as the example that they wanted. Commented Nov 20, 2018 at 18:10
  • I'm upvoting your answer. Mine works as well but yours is cleaner and less tedious. I'm aware of the pkill command but I use kill out of habit and didn't want to give misinformation as I didn't have a computer to test at the time. Commented Nov 20, 2018 at 19:52
  • I don't have an OSX system at hand, either, but I'm encouraged by the existence of the corresponding man page. Commented Nov 20, 2018 at 19:56
  • short n sweet ! Commented Nov 26, 2018 at 15:15
1

kill $(ps aux | grep ruby | grep -v grep | awk '{print $2}' | xargs)

for p in $(ps aux | grep ruby | grep -v grep | awk '{print $2}'); do kill $p; done

You can substitute kill9 for kill if necessary.

-1

I Tried with below command

ps -eaf | grep -i ruby| grep -iv 'grep'| awk '{print "kill -9" " " $2}'| sh 
3
  • awk can grep as well as execute system commands, which would remove three of the pipeline commands Commented Nov 20, 2018 at 17:57
  • I Added only awk method Commented Nov 20, 2018 at 18:09
  • ps -eaf | grep -i ssh| awk '$(NF-2) !~/grep/{print "kill -9" " " $2}'| sh Commented Nov 20, 2018 at 18:09

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.