# 当前login-shell的进程PID.
root@37C:~# echo $$
3016
# 测试脚本:
root@37C:~# cat run.sh
#!/bin/bash
# 获取执行shell脚本的非交互shell的PID.
echo $$
######
echo "test1:-------------------------"
ps -ef | grep `echo $$`
echo "test2:()-----------------------"
( pwd;echo $$; ps -ef|grep `echo $$`; )
echo "test3:{}-----------------------"
{ pwd; echo $$; ps -ef | grep `echo $$`; }
# 脚本执行结果:
root@37C:~# ./run.sh
# 或者
root@37C:~# bash run.sh
11299
test1:-----------------------
root 11299 3016 0 15:26 pts/4 00:00:00 /