'How to kill the pm2 --no-daemon process

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?



Solution 1:[1]

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).

Solution 2:[2]

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

Solution 3:[3]

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

Solution 4:[4]

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.

Solution 5:[5]

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

Solution 6:[6]

sudo pkill -f pm2

This should kill all processes of pm2 in linux

Solution 7:[7]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Abdulmoiz Ahmer
Solution 3 Pierre Ghislain
Solution 4 Sergey Yarotskiy
Solution 5 nima
Solution 6 Sehrish Waheed
Solution 7 pouria