How do you terminate a process in Python?
In Python, the method to terminate a process is by using the os.kill() function to send a signal to the specified process in order to stop it. Below is an example code demonstrating how to terminate a specified process.
import os
# 获取进程ID
pid = 12345
# 发送信号给进程来终止它
os.kill(pid, 9)
In the example above, replace the process ID with the actual ID of the process to be terminated. Then use the os.kill() function to send signal 9 to terminate that process.