Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)

share|improve this question
what's the command for a single file? – Avinash Raj May 19 '14 at 12:22
/usr/lib/R/bin/exec/R --slave --no-restore --file=fileName --args. I have many different possible arguments (each process takes a different argument name) – teaLeef May 19 '14 at 12:24
up vote 8 down vote accepted

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
share|improve this answer
It doesn't work. In fact, my command starts with usr/lib/R/exec/R for each process, but then each process has a different name since my script calls different arguments – teaLeef May 19 '14 at 12:27
Could you please attach in a the result of ps -aef with the 30 processes? – Sylvain Pineau May 19 '14 at 12:33 – teaLeef May 19 '14 at 12:36
Thanks, please retry with the updated pattern – Sylvain Pineau May 19 '14 at 12:38

Try this command,

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


pa aux | awk '/\/usr\/lib\/R\/bin\/exec\/R/ {print $2}' | xargs kill
share|improve this answer
Because in your question, you mentioned /usr/lib/R/exec/R but in your comment you mentioned /usr/lib/R/bin/exec/R – Avinash Raj May 19 '14 at 12:39
got: unexpected character '\' – teaLeef May 19 '14 at 12:43
please post the command you tried along with the output in pastebin – Avinash Raj May 19 '14 at 12:46 – teaLeef May 19 '14 at 12:56
now it is working. Sorry about the typos – teaLeef May 19 '14 at 13:14

You can use :

ps -ef| awk '/\/usr\/lib\/R\/bin\/exec\/R/ {print $2}' |xargs kill -9
share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.