Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill a NOHUP process for Node.js launched via SSH

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

like image 428
Saravanan Rajaraman Avatar asked Aug 06 '14 05:08

Saravanan Rajaraman


People also ask

How do I kill nohup processes?

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 kill a NodeJS process?

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.

How do you stop a node process?

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.


1 Answers

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

like image 92
Saravanan Rajaraman Avatar answered Oct 11 '22 08:10

Saravanan Rajaraman