解决方法
这是bash进程本身的进程标识.
您可以使用它来追踪您的过程 – 使用ps -p
查看是否仍在运行,使用kill发送信号(例如暂停过程),使用renice更改其优先级等等.
进程ID通常写入日志文件,特别是当脚本的多个实例一次运行时,以帮助跟踪性能或诊断问题.
这是the bash documentation概述特殊参数.
BASHPID
,由ghostdog74提及,在4.0版本添加.这是Mendel Cooper的Advanced Bash-Scripting Guide的一个例子,显示了$$和$BASHPID之间的区别:
#!/bin/bash4 echo "\$\$outside of subshell = $$" # 9602 echo "\$BASH_SUBSHELL outside of subshell = $BASH_SUBSHELL" # 0 echo "\$BASHPID outside of subshell = $BASHPID" # 9602 echo ( echo "\$\$inside of subshell = $$" # 9602 echo "\$BASH_SUBSHELL inside of subshell = $BASH_SUBSHELL" # 1 echo "\$BASHPID inside of subshell = $BASHPID" ) # 9603 # Note that $$returns PID of parent process.