I'm very new to Linux. And as a matter of fact I use Cygwin now and not Linux itself.

I'm trying to install RVM (Ruby Version Manager).

I was doing rm -r ./.rvm -i command. I wanted to remove .rvm folder and see how I'd been asked to delete or not a file/directory. I saw a few and stopped it with Ctrl+Z and then removed the whole .rvm folder with Windows Explored, just sent it to the recycle bin.

But when I wanted to exit the terminal with exit command I got a message that I had stopped jobs:

$ jobs
[1]+  Stopped                 rm -r ./.rvm -i

Here I read how to kill the stopped job:

kill `jobs -p`

But I decided to try it with pipe command syntax I read about here:

The output of each command in the pipeline is connected via a pipe to the input of the next command

So I did these attempts but couldn't get the desired result:

$ jobs -p | kill
$ jobs -p | kill -n 15 # 15 is SIGTERM signal
$ jobs -p | kill -n=15 # got error wrong signal spec
$ jobs -p | kill -s SIGTERM

And I don't understand why it doesn't work. jobs -p lists process IDs:

$ jobs -p

So that 340 ID has to go to the kill -n 15 command and it should kill the job. But it doesn't happen. Why? Is it possible to use pipe in this case?

  • Why not just fg the job? It does not answer your question, but it is one of the normals way to solve the 'you have stopped jobs' problem.
    – Hennes
    Mar 14, 2013 at 13:46
  • Just because I don't know fg command yet. Now I do :) Thanks.
    – Green
    Mar 14, 2013 at 13:49
  • In that case: you can background an already running process with control-Z, or a new process by adding an & behind the command. jobs should list these tasks. fg or fg 1 will bring the first background process back. (If you have more jobs then you can add a number to select which process needs to be foregrounded).
    – Hennes
    Mar 14, 2013 at 13:54

4 Answers 4

  • Commands have several standard streams: Standard Out (stdout), Standard In (stdin), and Standard Error (stderr).
  • Pipes send a command's stdout to another command's stdin
  • Kill takes its paramters through its argument list, not any of the "standard" streams
  • Some commands allow you to specify "-" on the argument to accept input from stdin as arguments (not the kill command)
  • If you want to pipe stdout to another's argument list, you can use xargs, but care must be taken when there are potential spaces-- and sometimes in other cases).

In your case, jobs -p shouldn't have any issues with xargs and you can use the following:

jobs -p | xargs kill

If you like, you can also see the exact commands it executes by using --verbose (or -t)

jobs -p | xargs --verbose kill
jobs -p | xargs -t kill

xargs is a powerful tool. Be very careful passing input to it (find -print0, grep -Z, and xargs -0 get along well when working with files). Its well worth the effort to utilize it (and sometimes, time saved).


kill doesn't take arguments from standard input, which is where they will appear if you pipe them as you have done. The only way to use kill is to specify a PID, or list of PIDs, as command-line arguments.


If SIGTERM (-15) does not work, then try SIGKILL (-9). It is recommended to try SIGTERM first though.

 kill `jobs -p`
 kill -9 `jobs -p`
  • 1
    Might want to add that using ` put the output of the jobs (in this case the PIDs on the command line. And not on std in/out.
    – Hennes
    Mar 14, 2013 at 13:57

In this case, you can just type: fg, then hit ctrl-C.

In case you want to directly kill your remaining process, under bash, you can easily issue a:

kill %1

Which will kill the first process in background, as identified by jobs.

  • Could you explain why you find this a better alternative than the ones from '13 and already accepted? Mar 24, 2015 at 14:14
  • Yes, there was a glitch: I meant: fg. Anyway, kill %1 will let you kill your first background process without having to find its PID. Mar 25, 2015 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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