• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • Life always offers you a second chance ... Its called tomorrow !!!

    Sunday, February 22, 2015

    How to check memory utilization for a specific process ?

    We have a no. of ways to check the overall memory usage but what if you want to monitor memory usage of some particular process.

    To show an example I am running screen utility on my machine so lets try to find the memory used by the same.

    The below command will create a screen with 50 lakhs line buffer by the name of "work"
    # screen -h 5000000 -LS work
    Once I execute this command a new screen will come up on the screen. To detach the screen press "ctrl + a + d"

    Now on the screen lets see the PID of the running screen utility
    # screen -ls
    There is a screen on:
            2598.work       (Detached)
    1 Socket in /var/run/screen/S-root.

    Here the pid for this screen utility is 2598

    Lets check the memory utilization of the same

    Method 1

    using ps command (this will show the memory utilization in percentage)
    # ps -p 2598 v
      PID TTY      STAT   TIME  MAJFL   TRS   DRS   RSS %MEM COMMAND
     2598 ?        Ss     0:03      0   354 938689 821540 42.9 SCREEN -h 5000000 -LS work

    So the screen utility is using 42.9% of my total available memory i.e. 1869 MB so screen is using 801 MB approximately.

    Method 2

    Using top command
    # top -p 2598
     PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
     2598 root      20   0  917m 802m  864 S  0.0 42.9   0:03.49 screen

    So the output is similar to what we saw using ps command and it again shows us the %age usage but again there is one more section of VIRT which tells you the virtual memory used by the screen utility.

    Basically Virtual memory is a logical combination of RAM memory and swap space which is used by running process.

    Method 3

    Run the below command using the pid of the screen utility process
    # cat  /proc/2598/status | grep -i VMSIZE
    VmSize:   939044 kB

    This will again show you the virtual memory used by the screen utility i.e. 917 MB

    To understand the difference between Physical Memory, Virtual Memory and Swap space follow the below link
    What is virtual memory, paging and swap space?


    Related Articles:
    How to clear cache memory in Linux
    How to increase Swap memory size in Linux
    What is buffers/cache in free command in Linux ?
    What is swappiness and how do we change its value?


    Follow the below links for more tutorials

    How to keep a process running after putty or terminal is closed
    How to change the MAC Address of Ethernet device in Linux?
    Step by Step CentOS 7 (64 bit) Installation Guide with Screenshots
    What is nice and how to change the priority of any process in Linux?
    How to use yum locally without internet connection using cache?
    What is umask and how to change the default value permanently?
    Understanding Partition Scheme MBR vs GPT
    How to find the path of any command in Linux
    How to configure a Clustered Samba share using ctdb in Red Hat Cluster
    How to delete an iscsi-target from openfiler and Linux
    How to perform a local ssh port forwarding in Linux
    How to do a case sensitive search inside vi editor in Linux
    How does a successful or failed login process works in Linux

    What is buffers/cache in free command in Linux ?

    When we run free command to view the memory usage in Linux we get a similar output as below
    # free -m
                 total       used       free     shared    buffers     cached
    Mem:          1869       1398        471          0         24        400
    -/+ buffers/cache:        974        895
    Swap:         3999          0       3999

    Now here most of the terms should be understood but ever wondered what is that buffers/cache ?

    Let me explain all the parameter used here

    total: It shows you the total memory assigned to your machine but again the value shown to you is not the real value as it excludes a small amount of RAM which is reserved for kernel as in my case my machine has 2048 MB but out of which it only shows me 1896 MB where 152MB is reserved by kernel for booting purpose

    used: The total used memory by the processes in your OS

    free: Memory not in use
    total (1869) = used (1398) + free (471)
    Now coming to -/+ buffers/cache

    First value i.e 974 in my case gives the original value of used minus the sum buffers + cached 
    ( 1398 - (400 + 24) ) = 974
    Second value i.e. 895 gives the original value for free plus the sum buffers + cached 
    ( 471 + 24 + 400 = 895 ) = 895
    Again the last section shows you the total assigned, used and free swap memory having no much of any mathematical calculation.

    How do you understand if your system is low on memory?

    This question can be a bit complicated to answer unless you understand the difference between Virtual memory, used memory and buffers/cache.
    Most of the time you observe the output of free command, free memory section will be low value but comparatively buffers+cache value would be higher. Now this is not a bad thing actually since your OS has reserved this memory to speed up your most used process by keeping them in the cache. But in case any new process is executed and your system is low on memory then these cache would be automatically released to make space for memory reservation of new processes.

    How to free cache memory?

    You can do this using the below command
    # echo 3 > /proc/sys/vm/drop_caches
    These are the different values which you can use with the above command
    echo 1 is clearing only page cache
    echo 2 is to clear free dentries and inodes
    echo 3 is clearing page cache, dentries and inodes


    Related Articles:
    How to clear cache memory in Linux
    How to increase Swap memory size in Linux
    What is virtual memory, paging and swap space?
    What is swappiness and how do we change its value?


    Follow the below links for more tutorials

    How to keep a process running after putty or terminal is closed
    How to change the MAC Address of Ethernet device in Linux?
    Step by Step CentOS 7 (64 bit) Installation Guide with Screenshots
    What is nice and how to change the priority of any process in Linux?
    How to use yum locally without internet connection using cache?
    What is umask and how to change the default value permanently?
    Understanding Partition Scheme MBR vs GPT
    How to find the path of any command in Linux
    How to configure a Clustered Samba share using ctdb in Red Hat Cluster
    How to delete an iscsi-target from openfiler and Linux
    How to perform a local ssh port forwarding in Linux
    How to do a case sensitive search inside vi editor in Linux
    How does a successful or failed login process works in Linux

    Monday, February 09, 2015

    How to configure and analyze kdump for kernel panic in Red Hat Linux 6

    Kdump is a kernel crash dumping mechanism that allows you to save the contents of the system's memory for later analysis. It relies on kexec, which can be used to boot a Linux kernel from the context of another kernel, bypass BIOS, and preserve the contents of the first kernel's memory that would otherwise be lost.

    In case of a system crash, kdump uses kexec to boot into a second kernel (a capture kernel). This second kernel resides in a reserved part of the system memory that is inaccessible to the first kernel. The second kernel then captures the contents of the crashed kernel's memory (a crash dump) and saves it.

    Memory Requirements for KDUMP

    In order for kdump to be able to capture a kernel crash dump and save it for further analysis, a part of the system memory has to be permanently reserved for the capture kernel. On some systems, it is possible to allocate memory for kdump automatically, either by using the crashkernel=auto parameter in the bootloader's configuration file, or by enabling this option in the graphical configuration utility.

    The amount of reserved memory is either determined by the user or is used, it defaults to 128 MB plus 64 MB for each TB of physical memory (that is, a total of 192 MB for a system with 1 TB of physical memory).
    Architecture
    Required Memory
    AMD64 and Intel 64 (x86_64)
    2 GB
    IBM POWER (ppc64)
    2 GB
    IBM System z (s390x)
    4 GB
    In order use the kdump service on your system, make sure you have the kexec-tools package installed. To do so, type the following at a shell prompt as root:
    # yum install kexec-tools
    You can configure the same using GUI console but for that make sure the below package is installed
    # yum install system-config-kdump

    Configure kdump

    Run the below command from your GUI console
    NOTE: Make sure you are in runlevel 5 before running the below command or else it will throw out an error.

    Tuesday, November 25, 2014

    Step by Step Red Hat Linux 7.0 installation (64 bit) with screenshots

    Here are the step by step screenshot for the installation of Red Hat Enterprise Linux 7 (64 bit). 

    The installation process is not much different as compared to "CentOS 7.0 (64-bit)" which I have explained in the below Article

    Once you insert and boot your machine with the RHEL DVD, you will get the below screen. Select "Install Red Hat Enterprise Linux 7.0" and Press "Enter".

    As you see the installation process is initiated

    Select the Language preference

    The Next screen contains almost all the configuration which has to be performed for the installation. Since we have already selected our Language and Keyboard preferences, we can skip that step here.

    Lets start by setting the Date and Time

    Select your Location as for me it is Asia/Kolkatta

    Next we will select the packages which we want to install. So Select "Software Installation" which will lead you to the below screen. In my case I will install the "Base Installation" package having "Server with GUI" and in case you want to add any extra Add On, you can select the same from the left panel as shown below.

    Next we need to configure partitions. So select "Installation Destination"

    Select the hard disk which you have used to install RHEL 7, as for my case as you can see 20GB hard drive.

    Also if you want the OS to automatically create the partition select the same or else for this article lets manually create the partitions

    You can create a partition with the below list of partition types. As for this article we will select LVM

    Click on the "+" sign to add new partition.

    For this article I will create /boot, /, swap partition under LVM with Volume Group name as "VolGroup00"

    Change the partition type to Ext4 as by default XFS will be selected for every partition you create.

    Once you change these settings make sure you "update settings"

    By default Volume Group name is "rhel". Let us change it to "VolGroup00"

    You can also configure the storage for RAID but let us skip that part as of now.

    As you see all the mount points as planned are created with below name under LVM
    VolGroup00-root
    VolGroup-swap

    Click on Done and select Accept Changes.

    The last one is to Configure Network

    Provide a hostname for your machine and enable the ethernet device. Next select Configure to configure network settings for your machine

    Change the Ethernet device name or else you can skip that part. Next configure you IP details as per your environment i.e IPv4 or IPv6. We are using IPv4 so selected the "IPv4 Settings" and added the IPNetmask,Gateway and DNS details in the same.. Click on "Done" to save the configuration and go a step back.

    So we are done here with all the options on this screen. Next we can "Begin Installation"

    As you see the installation has begun in the mean time you can add a password for your root user. Also you can create additional user by using the "User Creation" thumbnail.

    Provide a password for root account.

    Create a user.(Optional)

    In the mean time let the installation complete. Once done click on Reboot.

    Once the machine reboots, next it will prompt the below screen. Click on "License Information"

    Accept the Terms and Conditions

    Click on "Finish Configuration"

    Next you will get the Kdump configuration page.

    Let us enable the Kdump and let the machine decide the amount of memory required for the same.

    I do not want to register my system to RHN as for now,also we can perform this step later so let us skip this part for now.

    Next you get your Login Screen which means we have successfully installed our Operation System i.e. RHEL 7.0 (64 bit).

    Related Article:
    Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)

    Follow the below links for more tutorials

    How to find the path of any command in Linux
    How to configure a Clustered Samba share using ctdb in Red Hat Cluster
    How to delete an iscsi-target from openfiler and Linux
    How to perform a local ssh port forwarding in Linux
    How to use yum locally without internet connection using cache?
    What is umask and how to change the default value permanently?
    Understanding Partition Scheme MBR vs GPT
    How does a successful or failed login process works in Linux
    How to find all the process accessing a file in Linux
    How to exclude multiple directories from du command in Linux
    How to configure autofs in Linux and what are its advantages?
    How to resize software raid partition in Linux
    How to configure Software RAID 1 mirroring in Linux
    How to prevent a command from getting stored in history in Linux

    Monday, November 24, 2014

    How to keep a process running after putty or terminal is closed

    There can be many times where you are suppose to run some application or process in Linux but you don not want it to be terminated by logoff and session disconnection from putty.

    nohup command

    `nohup' runs the given COMMAND with hangup signals ignored, so that the command can continue running in the background after you log out.

    Syntax
    # nohup COMMAND [ARG]...
    If standard input is a terminal, it is redirected from `/dev/null' so that terminal sessions do not mistakenly consider the terminal to be used by the command.

    If standard output is a terminal, the command's standard output is appended to the file `nohup.out'; if that cannot be written to, it is appended to the file `$HOME/nohup.out'; and if that cannot be written to, the command is not run.  Any `nohup.out' or `$HOME/nohup.out' file created by `nohup' is made readable and writable only to the user, regardless of the current umask settings.

    If standard error is a terminal, it is normally redirected to the same file descriptor as the (possibly-redirected) standard output. However, if standard output is closed, standard error terminal output is instead appended to the file `nohup.out' or `$HOME/nohup.out' as above.

    For Example:
    In this case the output is appended to ~/nohup.out file
    # nohup less /var/log/messages
    nohup: ignoring input and appending output to `nohup.out'

    NOTE: nohup does not automatically put the command it runs in the background; you must do that explicitly, by ending the command line with an `&'.

    You can supress this message and restrict the command from producing or saving any output to nohup.out using the below commands and redirection
    # nohup seq 1223434 > file.txt </dev/null &>/dev/null &
    [1] 3185

    OR
    # nohup seq 1234568 > file.txt 2>&1  &
    [1] 3184

    OR# nohup seq 1234568 > file.txt 2>/dev/null  &
    [1] 3192


    Stadard in, out and err
    There are three standard sources of input and output for a program. The program usually prints to standard output, and sometimes prints to standard error. These three file descriptors (you can think of them as “data pipes”) are often called STDIN, STDOUT, and STDERR.

    Sometimes they’re not named, they’re numbered! The built-in numberings for them are 0, 1, and 2 for STDIN, STDOUT and STDERR respectively.

    disown command

    You can also use this command to run any process without any disruption of active terminal or session

    If run without any options disown removes the JobID from the list of active jobs. As for now lets see how it can run any process in the background even after the terminal is closed or logged off.

    Run a process in background
    # seq 1223434232 > file.txt &
    [1] 3879

    # disown -h 3879
    # top
      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
     3879 root      20   0  4084  564  512 R 99.0  0.1   0:23.00 seq

    After this I disconnected my complete session and re-logged in to verify if my process is still running
    # top
      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
     3879 root      20   0  4084  564  512 R 99.9  0.1   1:01.11 seq

    And yes its still in the running status.

    If you use disown command without any switch it will remove all the stopped jobs.

    For Example
    If any of your running process which is stopped by using (Ctrl + Z) can be seen by using
    # jobs
    [1]   Running                 seq 122354332 > file.txt &
    [2]-  Running                 seq 17653434232 > file.txt &
    [3]+  Stopped                 seq 127564232 > file.txt

    Run the disown command without any argument by default it will delete the last stopped processes which in our case is (3)
    # disown
    -bash: warning: deleting stopped job 3 with process group 3896

    In case you want to delete a particular stopped job
    # disown %3
    -bash: warning: deleting stopped job 3 with process group 3904

    To delete all the stopped jobs
    # disown -a
    -bash: warning: deleting stopped job 1 with process group 3915
    -bash: warning: deleting stopped job 2 with process group 3916
    -bash: warning: deleting stopped job 3 with process group 3917
    -bash: warning: deleting stopped job 4 with process group 3918


    Related Articles:
    10 examples to help you understand top command usage in Unix/Linux
    How to run a process in background or bring to foreground in Linux
    How to run any script or cron job in Linux for every second

    Follow the below links for more tutorials

    How to find the path of any command in Linux
    How to configure a Clustered Samba share using ctdb in Red Hat Cluster
    How to delete an iscsi-target from openfiler and Linux
    How to perform a local ssh port forwarding in Linux
    How to use yum locally without internet connection using cache?
    What is umask and how to change the default value permanently?
    Understanding Partition Scheme MBR vs GPT
    How does a successful or failed login process works in Linux
    How to find all the process accessing a file in Linux
    How to exclude multiple directories from du command in Linux
    How to configure autofs in Linux and what are its advantages?
    How to resize software raid partition in Linux
    How to configure Software RAID 1 mirroring in Linux
    How to prevent a command from getting stored in history in Linux