Technology

Harmony in Java community

Apache came up with a proposal to develop a open source implementation of Java called Harmony.

Though, Harmony FAQ shows that they are going to have tough time making sure that they are not voilating Sun's license.

Talking about license, there have been lot of discussions on Sun's license earlier also. There were efforts to develop a free Java implementation including GNU classpath and Kaffe but both of these were licensed under GPL.

The special thing about Harmony is that it is going to be released under Apache's license.

Though initiative of developing a free VM raises few thoughts:

  • Will it always be released at the same time as a new release of Java by Sun?
    I think not for now atleast. As it appears that development of Java VM is not a small task and to catch up with current state Java VM should take quite alot of time.
  • Can it be better than Java?
    No, as a mail archieve indicates, it has to confirm to J2SE specification or it can not be called "Java".
  • What will be the future of Java if this really "catches" up?
    There will be lot of diverse implementation of Java "like" platforms, each taking up code base of Harmony and implementing their own VM.

    Surely, this puts Sun into a interesting position.
    Sun has been trying to improve relationship with Open source people, inviting others to develop specification for their next java release, or contribute to it.

    I personally feel development of Harmony will create more diversification of Java community.

  • Google suggest shows incorrect result

    I was impressed by the intersting user interface of Google suggest. It uses XMLHttpRequest for making callback to Google and updates the search results on every key press.

    The JavaScript code within it, calls a routine callGoogle, which makes call in the following format (On typing goog in English locale): http://www.google.com/complete/search?hl=en&js=true&qu=goog. The URL returns two arrays, one with possible results and another with number of results.

    This interface was developed by one of the Google’s employee in his 20% time, which is a program where Google allows their employees to devote 20% of their working hours to any project they choose.

    But does this really shows the right results.

    Screenshot below shows 155,000,000 results for keyword "google" in Google complete and 281,000,000 results when searching the keyword in google.com itself.

    Exploring procfs

    Why this article
    I am trying to collect some tips for getting userland information from procfs.
    Warning: Information may be specific to kernel version 2.6

    What is this procfs all about
    Procfs is a virtual file system in linux, mounted in /proc and serves multiple purposes including access to kernel information in userland or for debuggging purpose.
    One of the feature which makes Linux special to me is access to process information in text stream. Lot of linux commands(ps, top, pstree etc) rely on this filesystem for information.

    The virtual file system...
    The files and directories of /proc filesystems are virtual because the data is not actually stored on any sort of permanent storage like a hard disk; instead, the directories, files, and data within them are created dynamically in memory from raw kernel data whenever you attempt to read from them.

    Mounting proc
    Check if you already have procfs mounted on your system(cat /etc/mtab|grep proc), otherwise mount it using the following command:
    mount -t proc proc /proc

    Process information
    Lot of commands including ps, top etc. retreive process information from this filesystem. Each process has an entry in /proc/ filesystem identified by it's pid.
    Following are the important files in /proc/ folder:

    pid/cmdline contains the command that was used to start the process (using null characters to separate arguments).

    /proc/pid/cwd contains a link to the current working directory of the process.

    /proc/pid/environ contains a list of the environment variables that the process has available.

    /proc/pid/exe contains a link to the program that is running in the process.

    /proc/pid/fd/ is a directory containing a link to each of the files that the process has open.

    /proc/pid/mem contains the memory contents of the process.

    /proc/pid/stat contains process status information.

    /proc/pid/statm contains process memory usage information

    Examples of getting process information are:

  • Some time back I got stucked in a tricky problem of determining whether any particular process is doing a core dump. After some research I noticed that per process flag in /proc/pid/stat file(8th attribute) gives quite a lot of "personal" information about process. This information can be parsed by doing a logical AND of per process flag with the following values:

    0x00000002 Process being created
    0x00000004 Exiting
    0x00000008 Dead
    0x00000040 Process using super user privilage
    0x00000200 Process dumping core
    0x00000400 Process received some signal
    0x00000800 Process allocating memory
    0x00001000 Killed for out-of-memory
    I picked up these flags from /usr/src/linux/include/linux/sched.h

  • /proc/[pid]/fd/ folder gives information about open files.
    To find out input files used by a process:
    ls -l /proc/[pid]/fd/0

    To find out socket used by a process:
    ls -l /proc/[pid]/fd|grep socket|cut -d: -f3|sed 's/\[//;s/\]//'

    Information about these sockets can be obtained from
    netstat -ae

  • To get command line arguments passed to any process:
    cat /proc/[pid]/cmdline
  • Getting parent process id of a process:
    grep PPid /proc/[pid]/status
  • General system information..
    Procfs is used to get lot of system information. This includes information on cpu load, file system information and networking configuration.
    Following are some examples of viewing or changing the system information using procfs:

  • To find out free system memory:
    grep Free /proc/meminfo
  • System statistics since it was last started can be collected from /proc/stat file. To find out number of processes system had since last reboot:
    grep processes /proc/stat
  • To find out one, five and fifteen minute system load average:
    awk '{"1 min:"$1"/n5 min:"$2"\n15 min:"$3}' /proc/loadavg
  • /proc/partitions can be used for getting system partition information.
  • /proc/net and /proc/sys/net can be used to view or modify important network information.
    To disable ping, As root do the following:
    echo 1> /proc/sys/net/ipv4/icmp_echo_ignore_all

    or to enable IP forwarding, IP Masquerade:
    echo 1 > /proc/sys/net/ipv4/ip_forward

  • Mounted filesystem information can be retreived from /proc/mounts
  • To change hostname on the fly do
    echo www.abc.com > /proc/sys/kernel/hostname
  • For getting CPU information:
    cat /proc/cpuinfo
  • To get swap space utilization
    cat /proc/swaps
  • To get System uptime
    cat /proc/uptime
  • To get File system being shared by NFS:
    cat /proc/fs/nfsd/exports
  • A bit of kernel information..
    Though I intend to cover it in some other article, here are some kernel titbits:

  • To get Version information of kernel
    cat /proc/version
  • The /proc/kmsg file is used by klogd as a source of kernel log information as an alternative to the syslog system call interface.
  • The /proc/kcore file provides access to the physical memory of the system in core file format, and can be used by gdb to examine the current state of any kernel data structures.
  • To get more information have a look at: /usr/src/linux/Documentation/filesystems/proc.txt

    I will try to look at this filesystem from kernel level in some future article.

    XML feed