How to Kill Processes in Batch?

I used the following bash code:

for pid in `top -n 1 | awk '{if($8 == "R") print $1;}'`
do
  kill $pid
done

It says:

./kill.sh: line 3: kill: 29162: arguments must be process or job IDs
./kill.sh: line 3: kill: 29165: arguments must be process or job IDs
./kill.sh: line 3: kill: 29166: arguments must be process or job IDs
./kill.sh: line 3: kill: 29169: arguments must be process or job IDs

Any ideas? Thank you!


Source: bash

Leave a Reply