""" @author: luojunhui """ import subprocess async def kill_task_by_name(task_name) -> bool: """ 通过进程名称来杀掉进程 :param task_name: """ try: # 构造命令 command = f"ps aux | grep {task_name} | grep -v grep | awk '{{print $2}}' | xargs kill -9" print(command) # 执行命令 result = subprocess.run(command, shell=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # 检查执行结果 if result.returncode == 0: return True else: return False except Exception as e: return False