Returns: - A list of process IDs that were terminated. """ terminated_pids = [] for proc in psutil.process_iter(['pid', 'name']): try: if proc.info['name'] == app_name: proc.terminate() terminated_pids.append(proc.info['pid']) except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): pass return terminated_pids
# Example usage if __name__ == "__main__": app_name = "chrome.exe" # Example application name terminated_pids = kill_all_processes(app_name) print(f"Terminated PIDs: terminated_pids") fe kill all
Here, pattern is the name of the process you want to kill. Returns: - A list of process IDs that were terminated
To kill a process named "firefox", use the following command: use the following command: