Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill a nohup process?

I executed the following command

$ nohup ./tests.run.pl 0 & 

now when I try to kill it (and the executions that are started from this script) using

$ kill -0 <process_id> 

it does not work. How can I kill a nohupped process and the processes that runs via the nohupped script?

Thanks

like image 819
polerto Avatar asked Nov 04 '11 09:11

polerto


People also ask

How do I kill a nohup process?

When using nohup and you put the task in the background, the background operator ( & ) will give you the PID at the command prompt. If your plan is to manually manage the process, you can save that PID and use it later to kill the process if needed, via kill PID or kill -9 PID (if you need to force kill).

Does Ctrl C kill nohup?

nohup prevents the process from receiving SIGHUP signal whereas CTRL+C sends SIGINT signal. That's why nohup doesn't have the effect you expected.

How do you stop BG process?

Use CTRL + Z Another method to put a process in the background is to use the CTRL + Z shortcut. Suppose we forgot to add the ampersand when running a program. To put the said process in the background, we can press the CTRL + Z key and suspend the job.

How do I know nohup is finished?

To check the results or status of the programs, log back in to the same server. Once the job has finished its output will be contained in a file located within your home space. The filename will be "nohup. out" (no quotes).

How to kill a process in the background using nohup?

When using nohup and you put the task in the background, the background operator (&) will give you the PID at the command prompt. If your plan is to manually manage the process, you can save that PID and use it later to kill the process if needed, via kill PID or kill -9 PID (if you need to force kill).

How do I get the PID of a process using nohup?

When using nohup and you put the task in the background, the background operator ( &) will give you the PID at the command prompt. If your plan is to manually manage the process, you can save that PID and use it later to kill the process if needed, via kill PID or kill -9 PID (if you need to force kill).

Why does kill report nohup 14224?

Your process 14224 is the grep nohup, as ps told you. So, when you get your prompt back, the grep ended and therefore, it is logical that kill reports that there is no such process. You will not see s process called nohup in your ps output. So, how to find the process to kill? As I don't have your beast-2, I will demonstrate with nohup sleep 99 &.

How to stop a nohup command?

You could also use the screen command to initialize a session, run your command and detach from the session. That way you can reconnect and see what's up. To stop the nohup, do a pgrep for the command you launched and kill it either by PID or name (using pkill).


2 Answers

kill -0 does not kill the process. It just checks if you could send a signal to it.

Simply kill pid, and if that doesn't work, try kill -9 pid.

like image 105
Mat Avatar answered Sep 28 '22 02:09

Mat


Simply kill <pid> which will send a SIGTERM, which nohup won't ignore.

You should not send a SIGKILL first as that gives the process no chance to recover; you should try the following, in order:

  • SIGTERM (15)
  • SIGINT (2)
  • SIGKILL (9)
like image 36
trojanfoe Avatar answered Sep 28 '22 01:09

trojanfoe