From: Sven Mascheck on
Mark Hobley wrote:

> However, if the subshell is actually the same process as the parent,
> I am wondering if it is possible to have both a shell and subshell
> running interactively.

They are not both running interactively, thoug, except the "child"
is in the background.
From: Christian Brabandt on
On 2010-01-08, Moody <nasir.mahmood(a)gmail.com> wrote:
> $ (echo $$)
> 17317
> $ echo $$
> 17317
> $

I believe that's why bash4 has $BASHPID:
#v+
chrisbra(a)t41:~$ echo $$ $BASHPID $( echo $$ $BASHPID )
15366 15366 15366 15421
chrisbra(a)t41:~$ bash --version
GNU bash, Version 4.0.33(1)-release (i486-pc-linux-gnu)
[�]
#v-

zsh has something similar with $sysparams[pid] in module zsh/system, I
think.

regards,
Christian
From: Kevin Collins on
On 2010-01-09, Sven Mascheck <mascheck(a)email.invalid> wrote:
> Moody wrote:
>
>> $ (echo $$)
^^
>> 17317
>> $ echo $$
>> 17317
>> $
>>
>> both shells have same pid, which I understand as same shell and not a
>> subshell..
>
> A subshell is "only" a new environment, which has a relationship
> like a child. But it's not a new child process. In regard to
> scripting this isn't necessary, but the isolated environment
> is usually sufficient. For a new process you should explicitly
> call a new shell or at least send the command into the background.

The problem above is that the '$$' in '(echo $$)' is expanded by the parent
shell before the sub-shell is spawned, which is why the same value shows up. I
can't think of a way to get the desired test accomplished :)

Kevin
From: Moody on
On Jan 12, 5:04 am, Kevin Collins <spamtotr...(a)toomuchfiction.com>
wrote:
> On 2010-01-09, Sven Mascheck <masch...(a)email.invalid> wrote:
>
>
>
> > Moody wrote:
>
> >> $ (echo $$)
>            ^^
> >> 17317
> >> $ echo $$
> >> 17317
> >> $
>
> >> both shells have same pid, which I understand as same shell and not a
> >> subshell..
>
> > A subshell is "only" a new environment, which has a relationship
> > like a child.  But it's not a new child process.  In regard to
> > scripting this isn't necessary, but the isolated environment
> > is usually sufficient.  For a new process you should explicitly
> > call a new shell or at least send the command into the background.
>
> The problem above is that the '$$' in '(echo $$)' is expanded by the parent
> shell before the sub-shell is spawned, which is why the same value shows up. I
> can't think of a way to get the desired test accomplished :)
>
> Kevin

This is true and even I can't figure out a new environment available
in sub shell. The reason being I need to execute my commend in
separate shell, is that my script when run has it's own name when I do
a "ps -ef|grep "the_process" "

what I have tried to do as workaround to this is to subtract 2 from
the count

like if I run the script and get a count of my scripts name
ps -ef|grep "the_process"

it gives me an actual count +2 but when I execute the same command at
the same time in another terminal, I can get an exact number which is
actually required.

Regards,
From: Stephane CHAZELAS on
2010-01-12, 00:04(+00), Kevin Collins:
[...]
> The problem above is that the '$$' in '(echo $$)' is expanded by the parent
> shell before the sub-shell is spawned, which is why the same value shows up. I
> can't think of a way to get the desired test accomplished :)
[...]

No, it's not, it's expanded by the subshell that may or may not
be a child process. Any other pid than $$ and $! are the shell's
internal cuisine's, one shouldn't need to deal with those.

You can always use:

sh -c '...whatever with "$$"...'

if you want to start a new shell and have a different $$.

--
St�phane