I start node.js
server has 3000 port by nohup for background running, but now i want to stop the node.js
server with 3000 and start again with the same port. How can I stop the process?
i can use this command for get the process to kill;
ps -a","ps -ef |grep nohup
but it return;
-bash: kill: (11929) - No such process
thanks
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).
To kill the main Node process, we just pass the pid of the main process. To see this in operation, replace the setTimeout function in our previous code example with this version that uses process. kill . This method also works in the REPL as well as in Node.
Method 1: Using ctrl+C key: When running a program of NodeJS in the console, you can close it with ctrl+C directly from the console with changing the code shown below: Method 2: Using process. exit() Function: This function tells Node. js to end the process which is running at the same time with an exit code.
Finally i got an solution for kill the node server which is run under nohup process
by the help of
start server @ background: https://stackoverflow.com/a/4018223/2616818
pid: https://stackoverflow.com/a/14152730
Kill: https://stackoverflow.com/a/8007409/2616818
1.Get the node process id by use
ps -ef | grep "node"
//9500 pts/0 00:00:00 .node.bin
2.Kill the process by
kill 9500
//you can use the PID to kill if not use kill -9 pid
for advanced use forever
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With