kill_office.py 826 B

1234567891011121314151617181920212223242526
  1. import logging
  2. import os
  3. import re
  4. import time
  5. import psutil
  6. logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
  7. def kill_soffice(limit_sec=12):
  8. pid_list = psutil.pids()
  9. for pid in pid_list:
  10. process = psutil.Process(pid)
  11. if re.search("soffice", process.exe()):
  12. start_time = process.create_time()
  13. now_time = time.time()
  14. run_time = now_time-start_time
  15. # logging.info("pid " + str(run_time))
  16. if run_time >= limit_sec:
  17. comm = "kill -9 " + str(pid)
  18. print("kill process ", str(pid), str(process.exe()), str(run_time), ">", limit_sec)
  19. os.system("echo $(date +%F%n%T)")
  20. os.system(comm)
  21. if __name__ == "__main__":
  22. kill_soffice()