70

I'm using pm2 as the process manager of Node.js.

In many cases, I think I will run it as a daemon process, but if you use it locally as debugging, I think that there are times when you use the --no-daemon option.

How do I end the process when moving pm2 with this --no-daemon option?

Junya Kono
  • 1,121
  • 3
  • 10
  • 16

8 Answers8

140

You can try:

pm2 kill

or find the running PM2 process with:

ps aux | grep PM2

then kill with:

kill -9 [pid]

The -9 switch sends the KILL signal to the process as opposed to the default interrupt (INT or SIGINT) signal and is equivalent to -KILL or -SIGKILL. Interrupt is a less invasive way and you could try that first to let the process gracefully exit, however, if it doesn't respond to that, the kill signal should result in an immediate termination (unless the process is zombie).

marekful
  • 14,986
  • 6
  • 37
  • 59
46

You can view all processes which are registered with pm2 using

pm2 list

Assume the process you want to stop is named as processA using the below command will stop the processA:

pm2 stop processA

In case you want to delete the process than use the below command:

pm2 delete processA

In case you don't want to kill a particular process but pm2 itself using the command below:

pm2 kill
Movahhedi
  • 302
  • 4
  • 15
Abdulmoiz Ahmer
  • 1,953
  • 17
  • 39
13

The right answer is pm2 kill

$pm2 kill
[PM2] [v] Modules Stopped
[PM2] Applying action deleteProcessId on app [all](ids: 0)
[PM2] hello ✓
[PM2] [v] All Applications Stopped
[PM2] [v] PM2 Daemon Stopped

Pierre Ghislain
  • 312
  • 2
  • 6
9

Other solution will be to run pm2 delete all or pm2 stop all. Which will not kill pm2 process itself, but will cleanup internal pm2's process list.

Sergey Yarotskiy
  • 4,536
  • 2
  • 19
  • 27
7

First of all list all processes:

pm2 list

let suppose if your process is dev

pm2 stop dev

Now, delete the process

pm2 delete dev

after that process state became daemon.

If you want to kill that daemon process then run command

pm2 kill
nima
  • 7,796
  • 12
  • 36
  • 53
Ejaz khan
  • 1,535
  • 8
  • 17
6
sudo pkill -f pm2

This should kill all processes of pm2 in linux

Sehrish Waheed
  • 1,230
  • 14
  • 17
0

One thing to add to the accepted answers. These commands only work for the current user. I had the same problem with a digitalocean droplet. I had logged in using "ubuntu" username, but I saw that the God Daemon is pointing to /home/nodejs/.pm2.

If this is the case, you need to switch to that user: sudo su nodejs And then run the pm2 kill commands from there.

pouria
  • 949
  • 8
  • 21
-4

If it's running in the foreground you should be able to kill it with ctl + c, same as you would kill node server.js.

Chase
  • 3,009
  • 3
  • 17
  • 23
  • I tried it. but, when I run `pm2 list` the status will be still online – Junya Kono Jul 20 '17 at 02:58
  • That should tell you that pm2 is not actually being run in the foreground. It has been daemonized into a background process. You should see it listed when running `top` or you can also search via @marekful 's suggestion above: `ps aux | grep PM2` to see if the pm2 process is running or not. What reason would you have for running it locally anyway? – Chase Jul 20 '17 at 03:05