1

So I made a program that opens tor browser and I need to kill that browser after some time how can I do that

I have tried to kill it with os.system and Linux commands

And this is command with whic I start the browser

    subprocess.call(['./start-tor-browser.desktop'])

2 Answers2

1

Take a look at the documentation for subprocess.call, it says:

Run the command described by args. Wait for command to complete, then return the returncode attribute.

subprocess.call waits for the command to finish, i.e until Tor is closed in your case. Instead, you can use the lower-level Popen API directly which lets you control the process after it's been spawned.

In that case, your code would end up looking something like this:

p = subprocess.Popen(['./start-tor-browser.desktop'])
# ...
# do other stuff here
p.kill()
Ammar Askar
  • 475
  • 3
  • 9
-1

On linux you can do

ps -fea | grep -i 'tor'
OR
pgrep applicationName

to find the process/pid. And to kill the tor process

kill <pid>

The command ps -fea | grep <process-name> will enumerate all processes running with name

hrmnjt
  • 183
  • 7