baudolino Posted January 21, 2003 Report Share Posted January 21, 2003 Want to know how to pipe the two commands below. The first one writes the pid of the process mpg123, the second one kills it. $ps -C mpg123 -o pid= 2206 $kill -9 2206 Tried $ps -C mpg123 -o pid= |kill -9 without success. Thanks. baudolino Quote Link to comment Share on other sites More sharing options...
fuzzylizard Posted January 21, 2003 Report Share Posted January 21, 2003 try this $ pd=`ps -C mpg123 -o pid=` | kill -9 $pd and see if that works. Quote Link to comment Share on other sites More sharing options...
baudolino Posted January 21, 2003 Author Report Share Posted January 21, 2003 :-( it doesn't Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted January 21, 2003 Report Share Posted January 21, 2003 Why not just killall -e mpg123 ? Quote Link to comment Share on other sites More sharing options...
aru Posted January 21, 2003 Report Share Posted January 21, 2003 why piping here? just use the output of your first command as a parameter for the second one: ~$ kill -9 $(ps -C mpg123 -o pid=) or ~$ kill -9 $(/sbin/pidof mpg123) but Steve Scrimpshire is right, the more stright forward way will be using /usr/bin/killall: ~$ killall -e -s SIGKILL mpg123 btw, usually SIGKILL (same as kill -9) is not a good idea since the process killed that way probably won't be able to close itself the right way. Is better to try to kill it with a signal 15 (SIGTERM), and if that doesn't work, then kill it with signal 9. Quote Link to comment Share on other sites More sharing options...
theYinYeti Posted January 21, 2003 Report Share Posted January 21, 2003 Yes, killall is easier, and try without -9 first. Also the $(ps ...) idea is good. Anyway if you still want to do this with a pipe, this should work: ps -C progname -o pid | xargs kill or ps -C progname -o pid | xargs kill -9 Yves. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.