Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
340

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?

share|improve this question
    
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 '13 at 13:46
    
Just because I don't know fg command yet. Now I do :) Thanks. –  Green Mar 14 '13 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 '13 at 13:54

3 Answers 3

up vote 2 down vote accepted
  • 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).

share|improve this answer

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.

share|improve this answer

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`
share|improve this answer
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 '13 at 13:57

Your Answer

 
discard

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.