echo $$ ; (echo $$)

echo $$ ; (echo $$)

Post by era eriksso » Wed, 12 Nov 1997 04:00:00




comp.unix.shell:
 > $ echo $$ ; (echo $$)
 > 11290
 > 11290

$$ is being expanded by the parent before the subshell is started.
If you really need to do this from the command line, try something
like

 $ echo $$ ; /bin/sh -c 'echo $$'
 13447
 13433

/* era */

--
 Paparazzi of the Net: No matter what you do to protect your privacy,
  they'll hunt you down and spam you. <http://www.iki.fi/~era/spam/>

 
 
 

echo $$ ; (echo $$)

Post by J. Wakeley Purp » Wed, 12 Nov 1997 04:00:00



>$ echo $$ ; (echo $$)
>11290
>11290
>$

>How to refer to the pid of the subshell?

As I remember reading in Bolsky & Korn, it's not guaranteed that
the (commands) construct will generate a separate shell, only that
'commands' will be executed atomically.

If you really _have_ to have a separate shell, do

        (ksh echo $$)

Of course I haven't tried it 8)
--



 
 
 

echo $$ ; (echo $$)

Post by David Boyc » Thu, 13 Nov 1997 04:00:00




> comp.unix.shell:
>  > $ echo $$ ; (echo $$)
>  > 11290
>  > 11290

> $$ is being expanded by the parent before the subshell is started.
> If you really need to do this from the command line, try something
> like

>  $ echo $$ ; /bin/sh -c 'echo $$'
>  13447
>  13433

The original poster is correct; ksh (and maybe the posix shell, I don't
remember) deliberately retain the same value for $$ within subshells,
and it's even documented to do so. Getting the pid of the child process
from within the child process is in fact a problem with these shells. I
wish I could provide an answer but cannot; maybe you could use some form
of shell IPC to send the value of $! from the parent to the child, but I
haven't tried this myself.

-David

 
 
 

echo $$ ; (echo $$)

Post by J. Kan » Thu, 13 Nov 1997 04:00:00




|>  >$ echo $$ ; (echo $$)
|>  >11290
|>  >11290
|>  >$
|>  >
|>  >How to refer to the pid of the subshell?
|>  >
|>  
|>  As I remember reading in Bolsky & Korn, it's not guaranteed that
|>  the (commands) construct will generate a separate shell, only that
|>  'commands' will be executed atomically.
|>  
|>  If you really _have_ to have a separate shell, do
|>  
|>   (ksh echo $$)
|>  
|>  Of course I haven't tried it 8)

It really doesn't matter whether the command is executed in a separate
shell or not -- what counts is where the command line is evaluted, which
in this case IS always the calling shell.

I don't understand the alternative suggestion -- as far as I can see,
you are looking for a file named echo, and executing the commands in it.

About the only way I can think of of doing it is sh -c 'echo $$', which
works.

--

GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
        I'm looking for a job -- Je recherche du travail

 
 
 

1. Local Echo vs Host Echo for tty's

This may be a dumb question but someone asked me the other day if we had
our terminals set up on our RS6000 for local echo or host echo. He told me
that if it was set up for host echo that we could improve the 'perceived'
performance to the user by setting up the terminal parameters to local
echo?

How do I check how I have my terminals set up now?

If it needs to be changed to local echo, do I use the stty command, and
what parameter? Or how is it done?

--
Brian Keith Smith
Carolina Handling, LLC
Charlotte, NC
1-704-357-6273

2. How to work with spaces in filenames

3. Looking for a brain-dead echo - i.e., an echo-like command that will pass \n

4. Linux NUMA on M68k?

5. ICMP echo and port 7 echo service

6. BIG IDE-Drive with Kernel 2.0.19

7. Linux 1.2.13: echo echoes \n

8. more than 26 SCSI disks

9. what causes kdm to echo "*" vs. no echo for password

10. diff among echo a>f; command<f; echo $a|command; command << $a; EOF

11. Q: What echoes faster than /bin/echo?

12. no echo when there should be echo

13. telnet echo on/off causes strange crlf echo