The old.sh
file contains the following code:
#!/bin/bash
echo $$
echo $PPID
(
echo $$
echo $PPID
)
bash /tmp/new.sh
The /tmp/new.sh
file contains the following:
#!/bin/bash
echo $$
echo $PPID
When I run the old.sh
file, this is the result:
632
143
632 # PID of subshell
143 # PPID of subshell
634
632
I expected that the PPID of the subshell would be equal to the PID of the main shell. However, the PID and PPID of the subshell and the main shell are the same.
Please explain why.