Currently I'm startin Tor as follows:

tor &

but this holds up the terminal and thus I need to press enter to continue. In a script this may not the desired behaviour, so I was wondering if it's possible to keep the script going after this.

I also tried with:

echo -ne '\n' | tor &

as explained around, but it doesn't make my script procedure. Any ideas on how to achieve what I explained?

  • Is this actually holding up the terminal? It seems more likely that you're just getting two processes writing output to the terminal at once clobbering each others output?
    – cacahuatl
    Commented Nov 28, 2016 at 23:33

1 Answer 1


From the Tor manual:

Other options can be specified on the command-line in the format "--option value", in the format "option value", or in a configuration file. For instance, you can tell Tor to start listening for SOCKS connections on port 9999 by passing --SocksPort 9999 or SocksPort 9999 to it on the command line, or by putting "SocksPort 9999" in the configuration file. You will need to quote options with spaces in them: if you want Tor to log all debugging messages to debug.log, you will probably need to say --Log debug file debug.log.


RunAsDaemon 0|1

If 1, Tor forks and daemonizes to the background. This option has no effect on Windows; instead you should use the --service command-line option. (Default: 0)

So tor --runasdaemon 1 should cause it to detach itself from the terminal and run itself in the background.

  • Ok. Can I simply kill tor afterwards with sudo pkill tor or you advise to do it in another way?
    – user13574
    Commented Nov 28, 2016 at 23:49
  • you shouldn't need root to kill it, if it's running as your user but pkill will work, pkill should be sending SIGTERM by default which Tor will trap on and exit cleanly. However, regexp based patterns might cause you to accidentally kill other matches. You may want to use tor's pidfile option to get it to write out it's process id to a file and then issue a command like kill -SIGTERM $(cat /path/to/tor.pid) assuming your pidfile is located at /path/to/tor.pid.
    – cacahuatl
    Commented Nov 29, 2016 at 0:26
  • Or you could use the control port. It's really up to you how to manage the process, normally each operating system has its own standard methods of maintaining and control system daemons.
    – cacahuatl
    Commented Nov 29, 2016 at 0:27

You must log in to answer this question.