假设我们有一个名为 qBittorrent 的应用程序,它允许我们在完成 torrent 下载后运行 shell 脚本。在编写由 qBittorrent 调用的 shell 脚本时,我们意识到拥有调用 shell 脚本的应用程序的 PID 会很方便——在本例中为 qBittorrent。
如何在 bash、zsh 或 sh 中实现这一点?
我在这里阅读了一些提示并遇到了
$PPID
。在 macOS 上,这给了我etc/launchd
而不是 qBittorrent。可能是 qBittorrent 正在调用 etc/launchd
来运行 shell 脚本……在那种情况下我需要返回父进程列表吗?