我试图获取当前正在执行的子shell的pid - 但$$只返回父pid:
#!/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
Run Code Online (Sandbox Code Playgroud)
产量
I am the parent shell …Run Code Online (Sandbox Code Playgroud)