[Ilugc] changing shell and finding it

benjamin benjaminrtz at gmail.com
Thu Jun 22 21:48:02 IST 2006

On 6/22/06, Gopalarathnam Venkatesan <gopal at gopalarathnam.com> wrote:
> 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.

$$ is the PID of the shell or script.

$PPID is   parent process id. For  login shell,  PPID  is pid of login

If "$$" is used within a shell procedure (script), it returns you the
> pid of the shell that was used to run the program.

When you run a script, login shell forks a new process and wait until it
finishes.  $$ within the script would be the PID of the scipt or new process
forked for the script itself.

benjamin rualthanzauva

More information about the ilugc mailing list