import logging import os import re import time import psutil logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') def kill_soffice(limit_sec=12): pid_list = psutil.pids() for pid in pid_list: process = psutil.Process(pid) if re.search("soffice", process.exe()): start_time = process.create_time() now_time = time.time() run_time = now_time-start_time # logging.info("pid " + str(run_time)) if run_time >= limit_sec: comm = "kill -9 " + str(pid) print("kill process ", str(pid), str(process.exe()), str(run_time), ">", limit_sec) os.system("echo $(date +%F%n%T)") os.system(comm) if __name__ == "__main__": kill_soffice()