0

So far, I have tried PSUTIL to see if firefox is running and it works, BUT the problem is firefox's PID keeps changing every time I close and reopen it. Is there anyway I can always check whether firefox is already running or not?

PS: Not using selenium right now, just my regular firefox browser

Ovicron
  • 91
  • 1
  • 4
  • 9
  • 1
    `psutil` is the right tool to do that. You can find more information in a [previous question](https://stackoverflow.com/questions/7787120/python-check-if-a-process-is-running-or-not/7788702). And why is it a problem that the PID is changing every time? – Emmanuel Di Pretoro May 16 '20 at 21:53

2 Answers2

0

You could try this in your python script :

l = [p.info for p in psutil.process_iter(attrs=['pid', 'name']) if 'firefox' in p.info['name']]
if(len(l)>0):
    print("Firefox is running")
else:
    print("Firefox is not running")
vbhargav875
  • 837
  • 8
  • 15
0
import psutil

for p in psutil.process_iter(attrs=['pid', 'name']):
    if p.info['name'] == "firefox.exe":
        print("yes", (p.info['name']))
Ovicron
  • 91
  • 1
  • 4
  • 9