Search code examples
macostormacos-sierranetstatlsof

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


I’m on Mac Sierra. I’m trying to start my Tor instance, but evidently it is already running on my computer …

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.

I tired to figure out what the PID is of the process running on the specified ports, but Mac tells me nothing …

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$ 

Any ideas how I can figure out what the PID is and kill it so I can start up Tor?


Solution

  • To find out which PID is using a particular port:

    $ lsof -t -i :9050
    

    The commands you've indicated are correct, so you might want to confirm whether or not lsof and netstat are actually working by doing a more generic command as a test, for example:

    $ lsof -i
    

    If that still doesn't return anything then you'll know the problem not isolated. Depending on your users permissions you might need to execute lsof or netstat with sudo:

    $ sudo lsof -i -P
    

    There's also the possibility neither returns anything because the port might not actually be open:

    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

    Confirm whether or not a torprocess is actually running per the notice:

    $ ps ax | grep tor