help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: value of $$ in backgrounded process


From: Kerin Millar
Subject: Re: value of $$ in backgrounded process
Date: Wed, 6 Oct 2021 21:07:03 +0100

On Wed,  6 Oct 2021 16:20:36 +0200 (CEST)
kovacs istvan <temezs2@freemail.hu> wrote:

> Hi,
> 
> I have been through the docs, but could not find clearly:

See the Special Parameters section [1].

> 
> what should $$ expand to in a backgrounded process?
> 
> Currently it will expand to the main process ID. Is this fixed, or 
> implementation specific?

That's as required by POSIX [2], which states that it "shall expand to the same 
value as that of the current shell". The bash manual is somewhat more pointed 
on the matter, stating that it "expands to the process ID of the invoking 
shell, not the subshell". As others have pointed out, bash offers BASHPID as an 
extension.

[1] https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html
[2] 
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_05_02

-- 
Kerin Millar



reply via email to

[Prev in Thread] Current Thread [Next in Thread]