Glam Prestige Journal

Bright entertainment trends with youth appeal.

I want to stop Node server on Linux, but when I try to stop it, it automatically starts again with a new PID. How can I stop this completely? Here you can see I tried to stop Nginx and Node process.

node server

I have tried tried these commands:

kill pid
Kill -9 pid
killall node <<command not working
killall -s KILL node <<< not working

When I tried to kill process 3814 it shows error No such process, how can I stop node server???

4

1 Answer

You are misunderstanding the output of ps. Your first command, sudo systemctl stop nginx is the right way to stop a running service and did actually work. The line you see in the ps isn't a running nginx process, that is the grep process you launched:

$ ps aux | grep foo
terdon 642773 0.0 0.0 8944 2384 pts/23 S+ 13:40 0:00 grep --color foo

When you run ps | grep, that is a process so that is also included in the output of ps. And, since your grep contains the string nginx, the grep itself is included in the output of grep. The usual ways around this are:

  1. Use pgrep instead of grep

     pgrep nginx

    That will only return anything (a list of PIDs) if there is a running nginx process.

  2. Use a character class in grep so that you can still match the process, but will ignore grep itself:

     ps aux | grep '[n]ginx'

Because the grep process now contains [n]ginx instead of nginx, it will not be matched by itself.

Since these are set up as services and, presumably, set to launch automatically, killing them just makes them restart. To stop them, you should always use systemctl stop nginx or, if your system supports it service nginx stop.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy