Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-08-2009, 01:01 AM   #1
Senior Member
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Rep: Reputation: Disabled
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.
Old 01-08-2009, 01:19 AM   #2
Didier Spaier
LQ Addict
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-14.2 on Lenovo Thinkpad W520
Posts: 7,621

Rep: Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558
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.

Last edited by Didier Spaier; 01-08-2009 at 01:19 AM. Reason: Typo
Old 01-08-2009, 01:37 AM   #3
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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
Old 01-08-2009, 01:46 AM   #4
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
There is also killall which will kill all processes by name.
killall -SIGQUIT ifstat


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: INPUT/OUTPUT error when remoting in saanjac Linux - Newbie 2 08-08-2008 03:38 PM
how to pass pipe output to file command nickleus Linux - General 6 06-19-2008 06:18 AM
bash input/output redirect problem greno Programming 2 12-31-2006 03:23 PM
bash: cd: /mnt/floppy/: Input/output error embsupafly Linux - Hardware 1 08-16-2003 06:36 AM
How do I pass a C variable to a Bash command ? Linh Programming 6 07-07-2003 03:12 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:50 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration