kill.py 522 B

12345678910111213141516171819202122
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import time
  4. import os
  5. def popen(command, bg=False):
  6. string = command
  7. if bg == True:
  8. command = command + ' &'
  9. process = os.popen(command)
  10. output = process.read()
  11. process.close()
  12. return output
  13. # 定时执行进程
  14. def process():
  15. check = 'ps -ef | grep task.cron | grep -v grep |awk \'{print $2}\''
  16. value = int(popen(check))
  17. if value:
  18. popen('kill ' + str(value))
  19. process()