我写了这段代码来检查'bad_process'是否正在运行:
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
因此,此代码可以检测 iTerm 是否正在运行,但 safari 没有运气: 结果与 iTerm 结果与 safari
所以,我可以使用 ps ea 检测 safari | grep safari,但我的代码没有运气。我应该改用 os.popen('ps ea | grep '+s) 吗?Safari 进程的 PID 的动态变化是否与我的情况有关?