When you run a process using nohup, the command makes the process ignore all termination signals, allowing it to continue running even after the session ends. If you need to terminate a process started with nohup, follow these steps:
- Find the Process ID (PID): First, locate the PID of the process you want to terminate. If you know the command used to start the process, use
pscombined withgrepto search for it. For example, if you started a program namedmyappwithnohup, run:
bashps aux | grep myapp
This lists all processes containing the myapp string. Typically, the PID appears in the second column of the output.
- Terminate the Process: Once you have the PID, use the
killcommand to terminate it. If the normal termination signal (SIGTERM, the default signal) is ineffective, send the SIGKILL signal—a forced termination signal that can terminate almost all processes:
bashkill -9 PID
Replace PID with the ID found in the first step.
Example
Suppose you run the following command using nohup:
bashnohup python myscript.py &
To terminate this process, follow these steps:
- Find the process:
bashps aux | grep myscript.py
- Assuming the PID is 1234, terminate it:
bashkill -9 1234
This way, even if the process was started with nohup, you can successfully terminate it.
2024年7月12日 16:43 回复