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 =======================================================

ebook:
Full Size
Jeep Buyer's
Guide
ebook:
Practical Suggestions
for Microsoft
Windows
Linux Tackles Microsoft
12 hour Video Course by john:
The Art of Linux System Administration
published by O'Reilly Media
Study Guide for the LPIC-2 Certification Exams
search for:
on the internet, or:
JohnMeister.com-fotos
LinuxMeister-Linux
BibleTech-
Bible overview


An overview of Biblical history:
"Promises and Prophets"

Wagoneers

FULL SIZE JEEPS

JeepMeister
"Jeep is America's
only real sports car."
-Enzo Ferrari


MeisterTech
Diesels +

One Page Overview of Linux Commands

click for an image of the 5 essential Linux commands

An Intro to Linux
AMSOIL product guide,
or, AMSOIL web, or 1-800-956-5695,
use customer #283461

Amsoil dealer since 1983
purchase AMSOIL
at Midway Auto on SR9 in Snohomish,
or at Northland Diesel in Bellingham, WA


SJ - 1962-1991

XJ - 1984-2001

WJ - 1999-2004

KJ - 2002-2007

WK - 2005-2010

Find the recommended
AMSOIL synthetics
for your Jeep

CJ-10A - 1984-1986

Jeepsters

MJ - 1984-1992

Willys - 1946-1965

Other Jeeps (FC)