Uzyskaj pid aktualnej podpowłoki

Próbuję uzyskać pid aktualnie wykonywanej podpowłoki - ale$$ zwraca tylko pid nadrzędny:

#!/usr/bin/sh

x() {
  echo "I am a subshell x echo 1 and my pid is $"
}

y() {
  echo "I am a subshell y echo 1 and my pid is $"
}


echo "I am the parent shell and my pid is $"
x &
echo "Just launched x and the pid is $! "

y &
echo "Just launched y and the pid is $! "

wait

Wydajność

I am the parent shell and my pid is 3107
Just launched x and the pid is 3108
I am a subshell x echo 1 and my pid is 3107
Just launched y and the pid is 3109
I am a subshell y echo 1 and my pid is 3107

Jak widać powyżej, kiedy biegnę$$ z funkcji, którą stworzyłem, nie wyświetla PID tak jak ja$! z powłoki macierzystej.

questionAnswers(5)

yourAnswerToTheQuestion