Free up Ram in Linux


If you are running out of RAM on your Linux system, you will want to find the culprit in order to solve the problem, either by reconfiguring the RAM-hungry application or by stopping it. First we need to find the processes which are taking the most amount of RAM.

1) List running processes sorted by RAM usage

in linux terminal type :
ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 20

image

Here it displays the top 20 processes by their RAM usage . If you want to change the no of processes to be displayed then change 20 to required numerical value. From here you can get the Process  Identifier(PID) of the signal which you want to free.
Instead of typing this command again and again , If you want to have your own custom command
refer to Create a Custom Linux Command using "alias" .


2) Kill the processes
There are different modes of killing a process . It can be kept in sleep mode , killed safely or forcefully killed .These modes are called signals. Signals are asynchronous events that can occur to a running process and may be caused by hardware, software or users. 
Signals are numeric integer messages that have been predefined so they understand what these signals mean. you use " kill -l ", or " trap -l " you can get a list of available signals.
type
kill -l    in terminal

The most general signals are
 0    EXIT     exit the program, not actual signal
 1     HUP    hang up, will actually cause a daemon to reread the configuration file
 2     INT   Interrupt or stop running, you can do this with Ctrl+C
 3    QUIT  quit key, CTRL+SHIFT or CTRL+SHFT+\
 9     KILL  stop immediately regardless of anything else, this is like an                   emergency kill switch
 15    TERM  terminate nicely if at all possible
 18    CONT  continue execution, this will start a stopped process
 20    TSTP  stop executing, continue
The kill command terminates a process. The syntax for Kill command
kill [-signal] process_identifier(PID)
Note that the signal is the number or the symbolic name of the signal to be sent.  The best way to use kill is to use kill followed by the process PID or Process Identification Number( which you get from step 1) .If you  want to kill  a process with PID 3349 , command :
kill 3349
Another way to do this is to use the -15  so it would look like this:
kill -15 3349
The default kill command uses -15 so that kill 3349 is the same as kill -15 3349.  The " -15 "  tells the process to stop just as if the user was logging out. The good thing here is that it will try to kill child processes as well.
The last alternative is the " -9 " option.  This will kill a process forcefully .
kill -9 3349

















AjSmart Tehnology geek

Sole blogger :(

No comments:

Post a Comment