Hi
I need to write a small script to kill the process id of particular job in one shot ,
Example
> ps
PID TTY TIME COMMAND
16280 pts/70 0:00 sh
16278 pts/70 0:00 rlogind
16197 pts/70 0:00 ps
1234 pts/70 0:00 runflow
2341 pts/70 0:00 runflow
12673 pts/70 0:00 runflow.
I need to kill runflow process id .Everytime to write all the prcosess id's of runflow is quite tedious as sometimes there are lot of runflow scripts running .
kill 1234 2341 12673
i tried to do but i am stuck ..
ps |grep "runflow" | cut -f2 -d' '
This will show the process id of run jobs , but i need all this to be arranged in a row and then i need to kill the process.
Please suggest .
Hi
Are you looking for something like this:
$ ps | awk '/runflow/{print "kill -9 ", $1}'
kill -9 1234
kill -9 2341
kill -9 12673
This output can be copied to a file, and you can run the file or you can run the command itself in backticks.
Guru.
ps -ef| awk '$NF ~ /runflow/ {print $2}'| xargs kill
Can also use the system() function inside awk to issue the kill. xargs would be redundant then.
Why not just use "killall runflow"?
edit: or pgrep
pgrep runflow | xargs kill
IMO the awk solutions just like greps need to use /[r]unflow/ to prevent the awk process itself from being killed.
---------- Post updated at 08:10 ---------- Previous update was at 08:06 ----------
Not all systems have killall and/or pgrep/pkill. Be careful where you run the killall command as it has a different meaning (oops) on at least an HPUX system:
killall(1M)
On AIX for example killall is not the same as on Linux. That's why it could be a reason to use it not for this purpose.