3

I have one command (/usr/lib/R/exec/R pathtoDifferentFiles) being executed with many different arguments (file names). Looking at htop, I see at least 30 processes created,

I want to kill all of them at the same time.

Is there a way to kill processes that apply a command starting with a pattern? (/usr/lib/R/exec/R)

teaLeef
  • 445

4 Answers4

8

Try using the pkill command:

pkill --full /usr/lib/R/bin/exec/R

From the pkill man page:

pkill will send the specified signal (by default SIGTERM) to each process.

[...]

  -f, --full
    The pattern is normally only matched against the process name.
    When -f is set, the full command line is
    used.

2

Try this command,

ps aux | awk '/\/usr\/lib\/R\/exec\/R/ {print $2}' | xargs kill

OR

pa aux | awk '/\/usr\/lib\/R\/bin\/exec\/R/ {print $2}' | xargs kill
Avinash Raj
  • 78,556
1

You can use :

ps -ef| awk '/\/usr\/lib\/R\/bin\/exec\/R/ {print $2}' |xargs kill -9
nux
  • 38,017
  • 35
  • 118
  • 131
  • How can I specify the pattern when I have different arguments names? /usr/lib/R/exec/R is common for all the processes, but then the command has different names for each process – teaLeef May 19 '14 at 12:26
  • try this command now – nux May 19 '14 at 12:29
  • I get: ps -ef|awk '/usr/lib/R/bin/exec/R/{print $2}' |xargs kill -9 awk: line 1: syntax error at or near { Usage: kill pid ... Send SIGTERM to every process listed. kill signal pid ... Send a signal to every process listed. kill -s signal pid ... Send a signal to every process listed. kill -l List all signal names. kill -L List all signal names in a nice table. kill -l signal Convert between signal numbers and names. – teaLeef May 19 '14 at 12:33
  • try the code now – nux May 19 '14 at 12:36
  • it doesn't do anything – teaLeef May 19 '14 at 12:44
  • @teaLeef if already all the process are closed, this doesn't do anything. – Avinash Raj May 19 '14 at 12:50
  • I tried before closing the processes – teaLeef May 19 '14 at 12:56
0

The killall command should do what you want:

killall /usr/lib/R/exec/R
zwets
  • 12,354