相关疑难解决方法(0)

获取当前子shell的pid

我试图获取当前正在执行的子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)

bash sh

26
推荐指数
2
解决办法
1万
查看次数

标签 统计

bash ×1

sh ×1