Pass output of one command as input to another on bash
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.
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.
You can also use a single command: pkill. Suppose you want to kill the processes using SIGABRT: you can do
There is also killall which will kill all processes by name.
killall -SIGQUIT ifstat
|All times are GMT -5. The time now is 02:36 PM.|