[Ilugc] changing shell and finding it

Gopalarathnam Venkatesan gopal at gopalarathnam.com
Fri Jun 23 09:26:17 IST 2006

R.Ramkumar wrote:
>> echo $$
> thats only the pid of the shell. as the faq mentioned by you says, u
> have to grep thru ps for this pid.
> that reminds me of the short cut for linux systems.
> `cat /proc/$$/exe`... gives u the path to the executable.
> read the file /proc/$$/cmdline till the first \0 for argv[0] of the shell..

"$$" is pid of the parent process, if you say "echo $$" from the shell 
prompt after logging in, it is the process id of the parent shell.

If "$$" is used within a shell procedure (script), it returns you the 
pid of the shell that was used to run the program.  For example, even if 
you use C-shell, but you ran the script using "sh shellproc", "$$" 
returns you the pid of "sh" (or bash/ksh depending upon your OS to which 
sh is linked to).

If the requirement is to print the login shell, its easy to grep 

Gopalarathnam Venkatesan


More information about the ilugc mailing list