【发布时间】:2021-08-13 20:09:47
【问题描述】:
获取和使用已安装程序(如 xed 或 Firefox)的真实 PID 运行良好 p.e.沿途:
#!/bin/bash
xed & PID=$! # Start xed and get PID for later
echo "$PID"
Running the xed some time
kill -15 "$PID" # Soft Kill of xed
获取便携式 TOR 浏览器的 PID 会返回一个看起来不是来自 TOR 浏览器的 PID(可能来自便携式 Tor 浏览器文件夹中的一个 TOR 帮助脚本)
这样做的结果是。 Tor 浏览器无法通过错误的 TOR PID 关闭:
#!/bin/bash
/home/username/desktop/Tor_FF/start-tor-browser.desktop & PID=$! # Start xed and get PID for later
echo "$PID"
Running the xed some time
kill -15 "$PID" # Soft Kill of xed
环境:
- Linux 类似 Ubuntu 64、20.x、Gnome
【问题讨论】:
-
试试
pgrep <name of the tor process>。对于名称,检查 .desktop 文件的内容或在 TOR 运行后查看top/pstree。 -
@Socowi,通过 pstree 和 top 手动获取真正的 PID 正在工作。 TOR 浏览器的进程名是 firefox.real。 pidof -x firefox.real 给了我4个不同的PID。对我有用的 TOR 浏览器的 PID 是这 4 个 PID 中的第 4 个。
-
我猜
pgrep -o firefox.real或-n应该可以解决问题。 -
@Socowi,现在我测试了它。它对我来说非常有用:PID=$(pgrep -o firefox.real); echo "$PID" 谢谢!!!