| | |
Kill top 5 processes
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
I guess something like this will work:
FYI this seems like a very bad idea. You could render your system useless if you kill the wrong process. The codes I posted above also depends on how your ps renders the data (linux, fbsd, unix, etc) so be sure to test.
I'm sure Salem will be along with a more graceful solution
bash Syntax (Toggle Plain Text)
sk@svn:~$ ps axu | grep -v ^USER | sort -k10 -r | head -n 5 root 4045 0.0 0.2 6428 1392 ? Ss Aug11 0:20 /usr/sbin/nmbd -D root 4293 0.0 0.0 0 0 ? S< Aug11 0:19 [smbiod] sk 18362 0.0 0.3 8180 1720 ? S Aug29 0:09 sshd: sk@pts/0 root 2246 0.0 0.0 0 0 ? S< Aug11 0:09 [kjournald] root 4085 0.0 0.1 2332 908 ? Ss Aug11 0:04 /usr/sbin/cron sk@svn:~$ ps axu | grep -v ^USER | sort -k10 -r | head -n 5 | awk '{ print $2 }' 4045 4293 18362 2246 4085 sk@svn:~$ ps axu | grep -v ^USER | sort -k10 -r | head -n 5 | awk '{ print $2 }' | xargs echo kill -9 kill -9 4045 4293 18362 2246 4085
FYI this seems like a very bad idea. You could render your system useless if you kill the wrong process. The codes I posted above also depends on how your ps renders the data (linux, fbsd, unix, etc) so be sure to test.
I'm sure Salem will be along with a more graceful solution
Sorts on the column -- in this case k10 is the cpu-time column. see `man sort`.
Please mark this thread as solved if you have found an answer to your original question and good luck!
Please mark this thread as solved if you have found an answer to your original question and good luck!
•
•
Join Date: May 2009
Posts: 9
Reputation:
Solved Threads: 1
what i meant to ask was wat does 10 denote here....is it that the CPU column started at 10th character position
It means the 10th column of data delimited by white spaces, not literally the 10th character from the left.
sk:~# ps axu | grep ^USER | sort -k10 -r
{1}USER {2}PID {3}%CPU {4}%MEM {5}VSZ {6}RSS {7}TTY {8}STAT {9}START {10}TIME {11}COMMAND•
•
Join Date: May 2009
Posts: 9
Reputation:
Solved Threads: 1
•
•
•
•
It means the 10th column of data delimited by white spaces, not literally the 10th character from the left.
sk:~# ps axu | grep ^USER | sort -k10 -r {1}USER {2}PID {3}%CPU {4}%MEM {5}VSZ {6}RSS {7}TTY {8}STAT {9}START {10}TIME {11}COMMAND
ps aux|sort -k 3 -g -r|head -n 6|awk '{awk print $2}'
![]() |
Similar Threads
- Killing Hidden Processes (C#)
- 100% CPU USAGE on and off! ;/ (Windows NT / 2000 / XP)
- Keep getting stupid ERROR messages (Windows NT / 2000 / XP)
- Internet Explorer & Windows Explorer (desktop shortcuts) Won't Load! (Viruses, Spyware and other Nasties)
- Windows XP wont shut down (Troubleshooting Dead Machines)
- Cant delete avi movie file! HELP (Windows NT / 2000 / XP)
- 100% cpu usage - spyware problem (Viruses, Spyware and other Nasties)
- ms config (Windows NT / 2000 / XP)
- CPU at 100% after installing broadband!?! (Windows NT / 2000 / XP)
Other Threads in the Shell Scripting Forum
- Previous Thread: cat . causes strange characters
- Next Thread: Record too long.......
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting






