Thursday, May 17, 2012

Show memory map of a process

How to show memory map of a process? or how to check how much memory a process is consuming?
Use pmap.

How to use pmap:

  1. get a pid of a process you are interested in checking, in this example apache:
    [mainuser@serverone ~]$ ps -eaf | grep http 
    root      1759  4493  0 04:02 ?        00:00:00 /usr/sbin/httpd
    apache    1760  4493  0 04:02 ?        00:00:25 /usr/sbin/httpd
    apache    1761  4493  0 04:02 ?        00:00:23 /usr/sbin/httpd
    apache    1762  4493  0 04:02 ?        00:00:21 /usr/sbin/httpd
    apache    1763  4493  0 04:02 ?        00:00:18 /usr/sbin/httpd


  2. run the pmap command against the PID number:
    [mainuser@serverone ~]$ sudo pmap 1760 | tail 
    97406000     28K r--s-  /usr/lib/gconv/gconv-modules.cache
    97463000     16K rw---    [ anon ]
    97467000 524288K rw-s-  /tmp/apc.tE1RRo (deleted)
    b7467000  11096K r----  /usr/local/zend/lib/libicudata.so.38
    b7f3d000      4K rw---  /usr/local/zend/lib/libicudata.so.38
    b7f3e000     64K rw-s-  /dev/zero (deleted)
    b7f4e000    504K rw-s-  /dev/zero (deleted)
    b7fcc000     32K rw---    [ anon ]
    bfd74000    144K rwx--    [ stack ]
    total  2742152K
     
  3. The process, which is apache is consuming about 2.7GB of memory
That's all folks :)


Friday, April 13, 2012

How to know if the machine you are working on are a VM

There are a few ways you can detect if the machine you are working on is a VM. Below are commands to use and the output if your machine is a VM:

  1. Use dmidecode command, dmidecode is a tool for dumping a computer DMI (some say SMBIOS) table contents in a human-readable format. So if your machine is a vm, you should not get any output:
    [somebody@theserver ~]$ sudo dmidecode
    # dmidecode 2.10
    /dev/mem: mmap: Bad address
  2. Try check on /proc/scsi/scsi, if it is a vm, you would not get any attached device:
    [somebody@theserver ~]$ cat /proc/scsi/scsi 
    Attached devices:

  3. Use lspci and see if there is any virtual related devices:
    [somebody@theserver ~]$ /sbin/lspci 
    00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
    00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
    00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
    00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
    00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
    00:02.0 VGA compatible controller: Cirrus Logic GD 5446
    00:03.0 Ethernet controller: Red Hat, Inc Virtio network device
    00:04.0 Ethernet controller: Red Hat, Inc Virtio network device
    00:05.0 SCSI storage controller: Red Hat, Inc Virtio block device
    00:06.0 RAM memory: Red Hat, Inc Virtio memory balloon
    00:07.0 SCSI storage controller: Red Hat, Inc Virtio block device
  4. Check on your network interface:
    [somebody@theserver ~]$ /sbin/ethtool -i eth0
    driver: virtio_net
    version:
    firmware-version:
    bus-info: virtio0
  5. Use dmesg and search for word virt, KVM, vmware, xen:
    [somebody@theserver ~]$ dmesg | grep -i vir
    Booting paravirtualized kernel on KVM
    CPU0: Intel QEMU Virtual CPU version (cpu64-rhel6) stepping 03
    input: Macintosh mouse button emulation as /devices/virtual/input/input1
    virtio-pci 0000:00:03.0: PCI INT A -> Link[LNKC] -> GSI 10 (level, high) -> IRQ 10
    virtio-pci 0000:00:04.0: PCI INT A -> Link[LNKD] -> GSI 11 (level, high) -> IRQ 11
    virtio-pci 0000:00:05.0: PCI INT A -> Link[LNKA] -> GSI 10 (level, high) -> IRQ
    [somebody@theserver2:~]$ dmesg | grep -i -e virt
    [ 0.000000] Booting paravirtualized kernel on Xen
    [ 0.102602] input: Macintosh mouse button emulation as /devices/virtual/input/input0
    [ 3.577404] Initialising Xen virtual ethernet driver

Wednesday, January 11, 2012

Ping a list of servers

To do this, you need to put all the hosts that need to be checked in a file. For example, I put all my hosts in a file called ping_list:

$ cat ping_list
cat.myhost.net
dog.myhost.net
tiger.myhost.net
bird.myhost.net
There are a few ways to ping multiple hostnames, I'll list out what I have tried before:

1. Use nmap
$ nmap -sP -iL ping_list
Failed to resolve given hostname/IP: cat.myhost.net. Note that you can't use '/mask' AND '1-4,7,100-' style IP ranges
Failed to resolve given hostname/IP: dog.myhost.net. Note that you can't use '/mask' AND '1-4,7,100-' style IP ranges
Host 192.168.0.99 is up (0.00036s latency).
Host 192.168.0.100 is up (0.00061s latency).
where -sP is for ping test and -iL is for inputting from files.

2. One liner for loop
$ for i in `cat ping_list`; do ping -c1 $i; done
ping: unknown host cat.myhost.net
ping: unknown host dog.myhost.net
PING tiger.myhost.net (192.168.0.99) 56(84) bytes of data.

--- tiger.myhost.net ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

PING tiger.myhost.net (192.168.0.100) 56(84) bytes of data.

--- bird.myhost.net ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
I believe there are other tools or scripts beside those I listed above, but I always these 2 methods to ping multiple hosts. If you have other tools or script, please leave a comment.

Thanks

Tuesday, December 6, 2011

Store svn password

To store your cert and password, all you have to do is:

1. Go to .subversion in your home folder

$ cd ~/.subversion
2. Run below command. This command will add store-auth-creds = yes and store-passwords = yes to your bottom of config file
$ echo -e "store-auth-creds = yes\nstore-passwords = yes" >> config
3. Run any svn command, and choose p for permanent accept certificate, and yes for storing your password.

Now you won't be asked for svn password anymore.

Friday, November 25, 2011

Add file type swap to linux

To add swap to linux machine:

1. Create a swap file. Size depends on your preference. Let's say we want to create a swap file with 8GB size (1024 x 1024 x 8 = 8388608).

# dd if=/dev/zero of=/swapfile bs=1024 count=8388608
where if is source, of is output file for dd to write to which is /swapfile in this case, bs is read/write byte size at a time and count is number of blocks.

2. Once created, make it a swap file
# mkswap /swapfile
3. Activate your swap file
# swapon /swapfile
4. Check your newly created swap space using free or top
# free -m
or
# top
5. To make it appear even after reboot, put it into fstab
# echo "swapfile swap swap defaults 0 0" >> /etc/fstab
It will look like this:
# cat /etc/fstab 
...
/swapfile1 swap swap defaults 0 0
...