Sponsored Content
Top Forums Shell Programming and Scripting Kill top 5 memory uses process Post 302947788 by bakunin on Monday 22nd of June 2015 09:29:58 AM
Old 06-22-2015
Quote:
Originally Posted by kki
i want to know is there any command or shell script for this to kill after finding top memories from server.
Of course there is, albeit i have to give the same warnings jiliagre and zaxxon already issued: don't do it, because this is not a sound procedure.

Look at the output of ps aux:

Code:
USER          PID %CPU %MEM   SZ  RSS    TTY STAT    STIME  TIME COMMAND
root       131076 12.0  0.0  448  448      - A      Jan 26 101800:17 wait
root      1048608 11.8  0.0  448  448      - A      Jan 26 99941:41 wait
root       983070 10.7  0.0  448  448      - A      Jan 26 90791:37 wait
root      1114146 10.7  0.0  448  448      - A      Jan 26 90765:00 wait
root      4587534  1.4  2.0 134488 134712      - A      Jan 26 11558:45 storstpd start
root     10158134  0.3  1.0 65976 66516      - A      Jan 26 2477:26 storapid st

You need the second column (the PID) for the kill command. Further, you need to disregard the first line because it contains headers rather than data:

Code:
ps aux | <some filter> ... |\
while read junk PID junk ; do
     echo kill -15 $PID
done

Your ps-output may differ slightly from mine (i took mine from an AIX system, not having a HP-Ux system at hand) and you might have to adjust the command slightly. There might be processes which do not respond to signal 15 (this would indicate poor programming) so you might need to change kill -15 <pid> to kill -9 <pid>. If you do so, programs will not be able to clean up after them: shared memory segments, FIFOs and the like as well as temporary files with be left over.

Test thoroughly before you remove the "echo"-statement. Even with thorough testing i suggest to never use this.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

When kill doesnt work, how to kill a process ?

Hi All, I am unable to kill a process using kill command. I am using HP-UX system. I have tried with kill -9 and i have root privilages. How can i terminate this daemon ? ? ? Regards, Vijay Hegde (3 Replies)
Discussion started by: VijayHegde
3 Replies

2. Shell Programming and Scripting

Kill a process without using kill command

Sorry, posted the question in other forum. (0 Replies)
Discussion started by: sudhamacs
0 Replies

3. Linux

Kill a process without using kill command

I want to Kill a process without using kill command as i don't have privileges to kill the process. I know the pid and i am using Linux 2.6.9 OS. (6 Replies)
Discussion started by: sudhamacs
6 Replies

4. Shell Programming and Scripting

Unix Script to find and kill a process with high memory utilization

Hi Unix Gurus i am somewhat new to unix scripting so need your help to create a script as below. # This script would find the process consuming memory beyond a certain #limit. if the meemory consumption is more than 100% for a period of 1 # minute for the specific process. the script would... (0 Replies)
Discussion started by: robinforlinux
0 Replies

5. AIX

Command to find TOP 5 Memory consuming process

HI All, Can anyone send me a command to find TOP 5 Memory consuming process. It would be lelpful if I get output something like below processname - pid - memory(in MB) - command I tried few commands from the internet but the result only give the real memory usage or pagging, I want total... (4 Replies)
Discussion started by: bce_groups
4 Replies

6. AIX

Need a list of top 10 CPU using processes (also top 10 memory hogs, separately)

Okay, I am trying to come up with a multi-platform script to report top ten CPU and memory hog processes, which will be run by our enterprise monitoring application as an auto-action item when the CPU and Memory utilization gets reported as higher than a certain threshold I use top on other... (5 Replies)
Discussion started by: thenomad
5 Replies

7. Shell Programming and Scripting

kill process from a file or directly with top

i have edited a script to kill an exact mysql process is causing the high load on the server, my problem is, kill dont kill it! script: #!/bin/sh top -n 1 -u mysql | grep mysqld | awk '{print $1}' > pid proc='cat pid' kill -9 $proc or i try with kill -9 `top -n 1 -u mysql | grep mysqld... (8 Replies)
Discussion started by: chandro
8 Replies

8. Shell Programming and Scripting

Cron job and shell script to kill a process if memory gets to high

Hello, I'd like to set a cron job that runs a shell script every 30 minutes or so to restart a java based service if the memory gets above 80%. Any advice on how to do this? Thanks in advance! - Ryan (19 Replies)
Discussion started by: prometheon123
19 Replies

9. Shell Programming and Scripting

Kill an specific process ID using the KILL and GREP commands

Good afternoon I need to KILL a process in a single command sentence, for example: kill -9 `ps -aef | grep 'CAL255.4ge' | grep -v grep | awk '{print $2}'` That sentence Kills the process ID corresponding to the program CAL255.4ge. However it is possible that the same program... (6 Replies)
Discussion started by: enriquegm82
6 Replies

10. Red Hat

How to find memory taken by a process using top command?

I wanted to know how to find the memory taken by a process using top command. The output of the top command is as follows as an example: Mem: 13333364k total, 13238904k used, 94460k free, 623640k buffers Swap: 25165816k total, 112k used, 25165704k free, 4572904k cached PID USER ... (6 Replies)
Discussion started by: RHCE
6 Replies
KILL(1)                                                            User Commands                                                           KILL(1)

NAME
kill - send a signal to a process SYNOPSIS
kill [options] <pid> [...] DESCRIPTION
The default signal for kill is TERM. Use -l or -L to list available signals. Particularly useful signals include HUP, INT, KILL, STOP, CONT, and 0. Alternate signals may be specified in three ways: -9, -SIGKILL or -KILL. Negative PID values may be used to choose whole process groups; see the PGID column in ps command output. A PID of -1 is special; it indicates all processes except the kill process itself and init. OPTIONS
<pid> [...] Send signal to every <pid> listed. -<signal> -s <signal> --signal <signal> Specify the signal to be sent. The signal can be specified by using name or number. The behavior of signals is explained in sig- nal(7) manual page. -l, --list [signal] List signal names. This option has optional argument, which will convert signal number to signal name, or other way round. -L, --table List signal names in a nice table. NOTES Your shell (command line interpreter) may have a built-in kill command. You may need to run the command described here as /bin/kill to solve the conflict. EXAMPLES
kill -9 -1 Kill all processes you can kill. kill -l 11 Translate number 11 into a signal name. kill -L List the available signal choices in a nice table. kill 123 543 2341 3453 Send the default signal, SIGTERM, to all those processes. SEE ALSO
kill(2), killall(1), nice(1), pkill(1), renice(1), signal(7), skill(1) STANDARDS
This command meets appropriate standards. The -L flag is Linux-specific. AUTHOR
Albert Cahalan <albert@users.sf.net> wrote kill in 1999 to replace a bsdutils one that was not standards compliant. The util-linux one might also work correctly. REPORTING BUGS
Please send bug reports to <procps@freelists.org> procps-ng October 2011 KILL(1)
All times are GMT -4. The time now is 02:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy