0

I'm wrote this code to check if 'bad_process' is running:

bad_process_list=['iTerm']
c = os.popen('ps ea')       #'ps aux' for complicated cases
for smth in c:              #make a timer to run fulltime
    for s in bad_process_list:
        if s in smth:
            print('close ', s,' right now!')
            break

so, this code can detect if iTerm running, but no luck with safari: result with iTerm result with safari

so, i can detect safari using ps ea | grep safari, but no luck with my code. should i use os.popen('ps ea | grep '+s) instead? is dynamic changing of PID of safari process alltime is associated with my case?

s1nceri7y
  • 1
  • 2
  • So you only need to check if safari is running? If you don' need portable code, you could use `pyobjc` instead and grab the running apps via Apple's native framework. – hoefling Jan 20 '18 at 12:23
  • @hoefling i thought I can use the same code for linux and macos. i want to write a small program which I could ran under any of these os. – s1nceri7y Jan 20 '18 at 12:55
  • Btw, `ps ea | grep safari` won't show you the safari process - it shows you the process of grep command you just started. Run `ps ... | grep [s]afari` to filter out the grep command and see the real findings. – hoefling Jan 20 '18 at 13:01
  • The only command working reliably at least for high sierra seems to be `ps -ef | grep -i [s]afari\.app`. – hoefling Jan 20 '18 at 13:06

0 Answers0