Timeline for How can I get the pid of a subshell?
Current License: CC BY-SA 4.0
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 20, 2024 at 12:44 | comment | added | Kusalananda♦ |
@AJM I'm assuming they corrected the documentation. Subshells are not just inside (...) but also, for example, in command substitutions ($(...)).
|
|
| May 20, 2024 at 10:34 | comment | added | AJM |
Looking at the manual and it just says "In a subshell" not "In a () subshell". However, an older version of the manual did say "() subshell". I wonder what's going on there?
|
|
| Sep 29, 2022 at 15:09 | comment | added | Kusalananda♦ |
@FranklinYu BASHPID was introduced in release 4.0. You are either unknowingly running some other shell, or an older version of bash.
|
|
| Jun 11, 2021 at 22:01 | comment | added | Franklin Yu |
When is $BASHPID introduced? It isn’t available in my Debian machine with Bash 5.0.
|
|
| Dec 1, 2018 at 12:52 | vote | accept | Tim | ||
| Dec 1, 2018 at 17:01 | |||||
| Nov 27, 2018 at 14:57 | comment | added | Kusalananda♦ |
@Tim The PID of a parent shell of a subshell can't reliably be found unless you arrange to save $BASHPID in a variable and use that in the subshell. There is $PPID, but that's the parent PID of the shell in the same sense that $$ is the PID of the shell (it's not reset in a subshell). There is no $BASHPPID variable.
|
|
| Nov 27, 2018 at 14:26 | comment | added | Tim | If I want to get the parent pid of a subshell, that is, the pid of the invoking shell of the subshell, do I have to use $$? Can I use something else which is more predictable? | |
| Nov 27, 2018 at 14:20 | comment | added | Kusalananda♦ | @Tim It depends on whether you, in a subshell, wants to get the process ID of the script or of the subshell. Both possibilities are provided and which is the correct one is dependent on the application. No more specific answer can be given to that. | |
| Nov 27, 2018 at 14:09 | comment | added | Tim | Do you mean I should always use $BASHPID in place of $$ in any case in bash? When shall I use which? | |
| Nov 27, 2018 at 13:42 | history | edited | Kusalananda♦ | CC BY-SA 4.0 |
added 117 characters in body
|
| Nov 27, 2018 at 13:36 | history | edited | Kusalananda♦ | CC BY-SA 4.0 |
added 185 characters in body
|
| Nov 27, 2018 at 13:34 | history | answered | Kusalananda♦ | CC BY-SA 4.0 |