乐闻世界logo
搜索文章和话题

How to get the process ID to kill a nohup process?

1个答案

1

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:

  1. 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 ps combined with grep to search for it. For example, if you started a program named myapp with nohup, run:
bash
ps aux | grep myapp

This lists all processes containing the myapp string. Typically, the PID appears in the second column of the output.

  1. Terminate the Process: Once you have the PID, use the kill command 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:
bash
kill -9 PID

Replace PID with the ID found in the first step.

Example

Suppose you run the following command using nohup:

bash
nohup python myscript.py &

To terminate this process, follow these steps:

  1. Find the process:
bash
ps aux | grep myscript.py
  1. Assuming the PID is 1234, terminate it:
bash
kill -9 1234

This way, even if the process was started with nohup, you can successfully terminate it.

2024年7月12日 16:43 回复

你的答案