Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-20-2009, 08:27 AM
|
#1
|
Member
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707
Rep:
|
echo $$
Dear all....
I have a file named new.sh which has executable permission, contents of the file is
./new.sh will give the PID of the shell in which new.sh executes....
. new.sh will be executed in current shell so it displays PID of current shell
But if i execute following on command prompt
First will display current shell's PID, its fine
Why second command will displays current shell's PID eventhough it executes in subshell ????
Last edited by vinaytp; 11-20-2009 at 08:29 AM.
|
|
|
11-20-2009, 10:18 AM
|
#3
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by David the H.
|
And so it does. My gast is flabbered
Code:
c:~$ echo $$
4128
c:~$ (eval echo '$$')
4128
|
|
|
11-23-2009, 01:54 AM
|
#4
|
Member
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707
Original Poster
Rep:
|
Dear all...
My doubt is not clear...
why
should give current shell's PID why not subshell's PID, as it executes in subshell
|
|
|
11-23-2009, 03:03 AM
|
#5
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by vinaytp
Dear all...
My doubt is not clear...
why
should give current shell's PID why not subshell's PID, as it executes in subshell
|
Because that is how bash is designed, as described in the link given by David the H. Surprised me.
|
|
|
11-23-2009, 04:19 AM
|
#6
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852
|
In other words, we don't know why exactly...only that the behavior is intentional. On another section of that page it says that $$ returns the PID of the parent process. Perhaps it's part of the posix specification or something.
Apparently Bash v.4 has a new $BASHPID builtin variable that can give you the subshell's PID.
|
|
|
11-23-2009, 05:35 PM
|
#7
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,443
|
My ghast hasn't been so flabbered in ages 
|
|
|
All times are GMT -5. The time now is 10:21 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|