为什么 "lsof" 不告诉我 运行 进程的 PID?

Why isn't "lsof" telling me the PID of the process that's running?

我在 Mac Sierra。我正在尝试启动我的 Tor 实例,但显然它已经 运行 在我的计算机上......

localhost:myproject davea$ tor --CookieAuthentication 0 --HashedControlPassword "" --ControlPort 9050 --SocksPort 50001
Nov 12 12:27:06.777 [notice] Tor v0.2.8.9 running on Darwin with Libevent 2.0.22-stable, OpenSSL 1.0.2j and Zlib 1.2.8.
Nov 12 12:27:06.778 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
Nov 12 12:27:06.778 [notice] Read configuration file "/opt/local/etc/tor/torrc".
Nov 12 12:27:06.782 [warn] Linelist option '__HashedControlSessionPassword' has no value. Skipping.
Nov 12 12:27:06.782 [warn] Option 'CookieAuthentication' used more than once; all but the last value will be ignored.
Nov 12 12:27:06.782 [warn] Linelist option '__HashedControlSessionPassword' has no value. Skipping.
Nov 12 12:27:06.782 [warn] ControlPort is open, but no authentication method has been configured.  This means that any program on your computer can     reconfigure your Tor.  That's bad!  You should upgrade your Tor controller as soon as possible.
Nov 12 12:27:06.783 [notice] Opening Socks listener on 127.0.0.1:50001
Nov 12 12:27:06.783 [notice] Opening Socks listener on 127.0.0.1:50001
Nov 12 12:27:06.783 [warn] Could not bind to 127.0.0.1:50001: Address already in use. Is Tor already running?
Nov 12 12:27:06.783 [notice] Opening Control listener on 127.0.0.1:9050
Nov 12 12:27:06.783 [notice] Opening Control listener on 127.0.0.1:9050
Nov 12 12:27:06.783 [warn] Could not bind to 127.0.0.1:9050: Address already in use. Is Tor already running?
Nov 12 12:27:06.783 [notice] Closing partially-constructed Socks listener on 127.0.0.1:50001
Nov 12 12:27:06.783 [notice] Closing partially-constructed Control listener on 127.0.0.1:9050
Nov 12 12:27:06.783 [warn] Failed to parse/validate config: Failed to bind one of the listener ports.
Nov 12 12:27:06.783 [err] Reading config failed--see warnings above.

我很难弄清楚指定端口上进程 运行 的 PID 是什么,但是 Mac 什么也没告诉我……

localhost:myproject davea$ 
localhost:myproject davea$ 
localhost:myproject davea$ lsof -i :9050
localhost:myproject davea$ 
localhost:myproject davea$ lsof -i :50001
localhost:myproject davea$ netstat -anp tcp | grep 50001
localhost:myproject davea$ netstat -anp tcp | grep 9050
localhost:myproject davea$ 
localhost:myproject davea$ 

知道如何找出 PID 并杀死它以便启动 Tor 吗?

找出哪个 PID 正在使用特定端口:

$ lsof -t -i :9050

您指定的命令是正确的,因此您可能想通过执行更通用的命令作为测试来确认 lsofnetstat 是否实际工作,例如:

$ lsof -i

如果仍然没有 return 任何问题,那么您就知道问题不是孤立的。根据您的用户权限,您可能需要使用 sudo:

执行 lsofnetstat
$ sudo lsof -i -P

也有可能 return 什么都没有,因为端口可能实际上没有打开:

Nov 12 12:27:06.783 [notice] Opening Control listener on 127.0.0.1:9050
Nov 12 12:27:06.783 [notice] Opening Control listener on 127.0.0.1:9050
Nov 12 12:27:06.783 [warn] Could not bind to 127.0.0.1:9050: Address already in use. Is Tor already running?
Nov 12 12:27:06.783 [notice] Closing partially-constructed Socks listener on 127.0.0.1:50001
Nov 12 12:27:06.783 [notice] Closing partially-constructed Control listener on 127.0.0.1:9050
Nov 12 12:27:06.783 [warn] Failed to parse/validate config: Failed to bind one of the listener ports.

Closing partially-constructed Control listener on 127.0.0.1:9050

根据通知确认 tor 进程是否实际上是 运行:

$ ps ax | grep tor