-   Linux - Newbie (
-   -   Pass output of one command as input to another on bash (

linuxlover.chaitanya 01-08-2009 02:01 AM

Pass output of one command as input to another on bash
Hello all,

I have a script that starts ifstat process everytime that script is run. I want to kill all the ifstat processes running.
I know I can get the process ids by pidof command. I want to pass the output of this command to kill so that all the processes are killed.
Is there anyway I can do this?
pidof ifstat. I get some pids then I pass these pids to kill.
I need to do this on bash first and then if this works for me I will use it in script for ifstat is running unnecessarily.

Didier Spaier 01-08-2009 02:19 AM

You ca do this
pidof <program_you_want_to_kill>|xargs kill

As usual you can know more with man <command> or info <command>.

I must admits that the output of "man bash" may be difficult to swallow at once ... So you will find guides you need at The Linux Documentation Projects.

To begin with I would suggest reading "Introduction to Linux - A Hands on Guide" from Machtelt Garrels.

colucix 01-08-2009 02:37 AM

You can also use a single command: pkill. Suppose you want to kill the processes using SIGABRT: you can do

pkill -SIGABRT ifstat
use either the signal name or its numeric id. To get a list of all the signals, take a look at

man 7 signal

jschiwal 01-08-2009 02:46 AM

There is also killall which will kill all processes by name.
killall -SIGQUIT ifstat

All times are GMT -5. The time now is 12:15 AM.