xargs to kill
ps -ef | grep XXXX | grep -v root | awk '{print $2}' | xargs kill
(replace XXXX with search string to kill...)
ps -ef | grep user | grep -v root | awk '{print $2}' | xargs kill
>--> ps -ef | grep user
root 9758 24722 0 11:36:17 pts/10 0:00 grep user
user 9755 9705 0 11:36:09 pts/7 0:00 vi test
user 9705 24365 0 11:34:20 pts/7 0:00 -ksh
user 9756 9705 0 11:36:13 pts/7 0:00 vi test2
>--> ps -ef | grep user | grep -v root
user 9755 9705 0 11:36:09 pts/7 0:00 vi test
user 9705 24365 0 11:34:20 pts/7 0:00 -ksh
user 9756 9705 0 11:36:13 pts/7 0:00 vi test2
>--> ps -ef | grep user | grep -v root | awk '{print $2}'
9755
9705
9756
why kill processes?
>--> w
10:28am up 171 day(s), 2:27, 7 users, load average: 4984.87, 4406.36, 3186.89
10:37am up 171 day(s), 2:36, 8 users, load average: 4880.55, 4189.25, 3535.02
User tty login@ idle JCPU PCPU what
...because sometimes user code can run amok... a user process kept spawning
off processes that resulted in this system load!
tried this, should have worked... but didn't on the specific application,
this is a variation of the other script in this directory that did work...
October 2004 - john
>--> more kill-defunct.sh
#!/bin/sh
echo "kill defunct processes"
while (ps -e | grep defunct)
do (
echo " killing defunct process(es)... "
ps -e | grep defunct | awk '{ print "/usr/bin/kill -9 " $1 }' > /tmp/killit
sh /tmp/killit
# cat /tmp/killit
/usr/bin/rm /tmp/killit
sleep 5
ps -e | grep defunct
)
done
(NOTE: this is from Solaris 2.6)
script to kill off stray (unattached) processes left from failed connection.
(best to fully resolve all commands, shown here in shorter form for clarity)
#!/bin/sh
echo "testing health - listing ps & users"
w | grep -v root | sort
ps -aux | grep -v root | grep -v bin | sort
#
while (ps -aux | grep -v root | grep -v bin | grep ?)
do (
echo " killing the unattached process(es)... "
ps -aux | grep -v root | grep -v bin | grep ? | awk '{ print
"/bin/kill -9 " $2 }' > /tmp/killit
sh /tmp/killit
/bin/rm /tmp/killit
sleep 5
w | grep -v root | sort
ps -aux | grep -v root | grep -v bin | sort
)
done
=======================================================
john meister sr CAD sys admin
=======================================================
|