我需要在脚本本身内部获取Shell脚本的PID,并需要将其传递给另一个脚本。
如何在脚本本身中获取特定脚本的PID?
最佳答案
可以使用os.getpid()
检索当前进程的进程ID。
import os
print("This process has the PID", os.getpid())
在bash中,您可以使用
$$
来获取运行脚本的bash实例的PID。
关于python-3.x - 在脚本本身内部获取shell/python脚本的PID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32649125/