Twitter Updates

    follow me on Twitter

    G-AVLN in front of her home

    G-AVLN in front of her home

    Mostly Unix and Linux topics. But flying might get a mention too.

    Tuesday, August 01, 2006

    Which shell?

    Finding which shell you are currently using is not difficult, the ps command can tell you this easily. However, if you are using several shells, identifying the current one can be rather involving, may require ps -f, to make sure that you are looking at the last one executed. his method has one inherent problem - relies on human ability to deduce the desired result. Approach very much prone to mistakes!

    Whenever possible make the system do the hard work for you. We know that the current process ID is stored in the environmental variable $. You can therefore always check what the PID of the current shell is with:

    $ echo $$

    PID itself does not tell you which shell this is (if you have a mix of ksh, bash or any other you are still nonthewiser which one of them corresponds to the PID). Yyou can find the name of the process name ellegantly by interrogating the /proc filesystem, which stores all process information (in both UNIX and Linux, but on Linux has also all sorts of other hardware information).

    Still using a reference to the $ variable, look in the /proc for the name of the corresponding program:

    $ ls -l /proc/$$/exe

    lrwxrwxrwx . . . /proc/25541/exe -> /bin/bash


    If this is something you need to execute regularly, you can always create a little function and place it in one of the environmental files...

    No comments:

    Blog Archive