daemon.py 709 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import time
  4. import os
  5. timeSleep = 15
  6. def popen(command, bg=False):
  7. string = command
  8. if bg == True:
  9. command = command + ' &'
  10. process = os.popen(command)
  11. output = process.read()
  12. process.close()
  13. return output
  14. # 定时执行进程
  15. def process():
  16. command = 'php /www/api/src/dai/seller/index.php \'{"l":"task.cron"}\' 1>/dev/null 2>&1 &'
  17. check = 'ps -ef | grep task.cron | grep -v grep | wc -l'
  18. i = 0
  19. while 1:
  20. value = int(popen(check))
  21. if value == 0:
  22. popen(command)
  23. time.sleep(timeSleep)
  24. process()