How to kill Respawning Node - node.js

Need help for killing process node JS.
I'm trying to stop node js process on my server,
I've been use
killall -9 node
and here is the response
node(30332): Operation not permitted
node: no process found
So I used
sudo killall -9 node
but the node js is still respawning with different PID. Any help?

Finally found the problems, there are Parents ID that related to Node Process.
I'm using
ps -ef | grep no
and found the Parent Process ID / Sleep Process and kill the parents and then kill the node process.

You can use process.kill() or process.exit() to kill/stop node process internally when there is stop request.
To stop all node process from command line use pkill node(in linux).

Related

Linux process automatically starts again with new new PID after killing

I wanna stop Node server on linux but when I try to stop it, It automatically starts with new PID how can I stop this completely. Here you can see I tried to stop Nginx and Node.
How can I check if it is a linux zombie process? If yes then How can I kill it? otherwise
I have tried tried these commands.
kill pid
Kill -9 pid
killall node <<command not working
This was spawn by it's parent process, I search out parent process after killing that this stop as well.

cannot kill node processes on ec2 instance

I cannot kill a node processes on my amazon ubuntu ec2 instance.
Here's what I've tried
ps aux | grep node --returns a process id
sudo kill -9 process id
each time it says no process found and then after
ps aux | grep node
the process has a new id
top shows that the process does not exist also.
I also tried these
killall node
pkill node
I also rebooted the server same problem.
pm2 was installed, but I uninstalled it.
I also discovered that on looking up the parent processes of the node process using
ps -o ppid=the process id
there are two parents a sshd and a bash process

How to kill Node Express child process?

Inside one Node/Express server, I started another Node/Express server as child process:
let appifi = child.spawn('node', [babel_path, www_path], {
cwd: appifi_path,
env: appifi_env,
})
This worked fine and appifi got a pid, say 2376.
When trying to stop the child process, appifi.kill() will kill the process with pid 2376, but there is a respawned server process running, usually with a pid equals to it's parent's pid plus 5 (I don't know if this is a strict rule).
My question is, how to kill them both in parent server? is it safe to process.kill(appifi.pid + 5)? or there are any better ways?
You can kill both (actually, ALL) node servers by killall -9 node

How to kill(if process exist) & restart a process in a single command line

I am in situation where i want to kill a process if exist & restart the same. How to do it?
currently i am doing this
killall -9 inetd && /bin/inetd
If inetd is not running i get this
killall: /bin/inetd: no process killed
Even though inetd is not running i want the above command to be successful.
Use ;
killall -9 inetd; /bin/inetd

Shell Script for Killing PID

I run a few processes that I created myself on my Ubuntu Server, and to kill them I run:
sudo fuser -n tcp PORT
kill -9 PID-DISPLAYED
Is there any way I can obtain the PID from a port using a shell script, then kill it by running the shell script.
Thanks.
fuser can kill it:
-k, --kill
Kill processes accessing the file. Unless changed
with -SIGNAL, SIGKILL is sent. An fuser process
never kills itself, but may kill other fuser processes.
The effective user ID of the process executing fuser is
set to its real user ID before attempting to kill.
Try using either killall, or pkill, either of which will close all processes of the type of argument you describe, for example:
killall firefox
Will kill all running instances of firefox.
See
this link of pkill.

Resources