How do I kill a stopped forever.js daemon? - node.js

So, I accidentally started a duplicate script using forever.js, and now forever list shows the same script on two processes.
Short of uninstalling forever, how can I simply kill a process/remove it completely, not just stop it?

Best I have found is to do
ps -eaf
Then just
kill <thePidYouJustGot> eg. kill 30566
Now it should be gone from forever list. :)
NOTE: if your script is not currently stopped doing this will not stop it! It will only remove it from 'forever list'! (But you can stop it yourself by also killing it with it's PID.)
(Optional)
For fun, this should also return the pid of the forever process for the desired entry:
ps -ef | awk '$NF=="myScript.js" {print $2}'
NOTE: replace 'myScript.js' with the location/file you used in the 'forever start' command. (You can find this with forever list under the script column.) It might be something like 'myServer/myScript.js'.

Related

how to force stop Intellij on linux

I am using a scratch file for some Kotlin work.
I accidentally created an endless loop in one of my functions and ran the file, so Intellij is not responding.
There is no button for stopping the execution of the scratch file and even if there were, that wouldn't work because Intellij is not responding to mouse clicks.
How do I force stop or restart Intellij in this case?
You can kill the process by name using
pkill -9 intellij
or by
killall -9 intellij
or even
kill -9 $(ps aux | grep intellij | awk '{print $2}')
You first need to find Intellij's process id:
ps -f | grep -i intellij
and then kill the process id (PID):
kill -9 PID
Already good answers are given above.
Another great way to find IntelliJ PID is to use htop command on Linux.
Install htop with the command: sudo apt install htop
Run htop in terminal
In the tabular format, PID is associated with each process including IntelliJ.
Run kill -9 <pid_of_intellij> to kill the IntelliJ process.
You can use xkill
then move the cursor from X to the window you need for example with (ide)
This works provided that you are not completely frozen OS

How to remove stopped process from forever list node js

remove stopped processes
Im using forever to keep node.js app running in the server. Is there a way to remove stopped processes from forever list?
Best I have found is to do ps -eaf
Then just kill eg. kill 30566
Now it should be gone from forever list. :)
NOTE: if your script is not currently stopped doing this will not stop it! It will only remove it from 'forever list'! (But you can stop it yourself by also killing it with it's PID.)
(Optional)
For fun, this should also return the pid of the forever process for the desired entry:
ps -ef | awk '$NF=="myScript.js" {print $2}'
NOTE: replace 'myScript.js' with the location/file you used in the 'forever start' command. (You can find this with 'forever list' under the script column.) It might be something like 'myServer/myScript.js'.
Execute forever list and get the desired process pid from the list (Eg. First column as in the below image)
Execute kill <pid> in the terminal to remove the stopped process from forever list

How to identify a job given from your user account and kill it

I had given a job in a remote server yesterday from my home. The command was
sh run.sh >& out &
The run.sh will excute a program (average.f) more than 1000 times recurssively.
Today, in my office, I found some mistake in my run.sh. So I would like to kill it.
I used top command, but it is not showing the run.sh. It is only showing average.f. So, once, I killed it with kill PID, it is again starting average.f with another PID and producing outputs.
ps -u is not showing either run.sh or average.f.
Can anybody please help me how to kill this job.
find your job id with the process or application name . example is given below - I am killing java process here
ps -aef|grep java
// the above command will give you pid, now fire below command to kill that job
kill -9 pid
// here pid is a number which you get from the first command
ps -ef | grep run.sh | grep -v grep | awk '{print $2}' | xargs kill -9
Use pstree(1) (probably as pstree -p) to list the process tree hierarchy, then kill(1) (first with -TERM, then with -QUIT, and if that does not work, at last with -KILL) your topmost shell process running run.sh (or else the few "higher" processes). Perhaps use killall(1) or pidof(1) (or pgrep(1) or pkill)
You might want to kill the process group, with a negative pid.
You should never at first kill -KILL a process (but only at last resort); some programs (e.g. database servers, sophisticated numerical computations with application checkpointing, ...) have installed a SIGTERM or SIGQUIT signal handler to clean up their mess and e.g. save some state (on the disk) in a sane way. If you kill -KILL them, they could leave the mess uncleaned (since SIGKILL cannot be caught, see signal(7)....)
BTW, you should use ps auxw to list all processes, read ps(1)

How to stop a forever process knowing the name

I have a node script in which I need to stop a forever process, before uploading the new version and restart it again;
the problem is that I only know the name of that process, and
forever stop processName.js
doesn't work, since it expect the index or the uid;
is it possible to stop it knowing only the name?
Finally I got it, using a variable:
uid=$(forever list | grep processName.js | cut -c24-27) && forever stop $uid
forever stop /home/user/server/script.js (full path)
You can also assign a unique id for the process while starting it, and then can close it using this. It looks for existing process by uid, and stops it, if it is running. Then it will start forever again with the same unique name.
if forever list | grep 'my-unique-process'; then forever stop my-unique-process; fi
forever -a --uid my-unique-process start app.js
Explanation:
If the process is running, then close it. If you close it while it's not running, it will throw an error
Forever cannot find process with id
The first line looks for the output of forever list command and matches the process name. Simple if-else of shell.
In the second line, the -a will append to the log. If you don't use -a, it sometimes gives error that 'Log file already exist'
--uid is used to assign a unique id to the process.

Howto debug running bash script

I have a bash script running on Ubuntu.
Is it possible to see the line/command executed now without script restart.
The issue is that script sometimes never exits. This is really hard to reproduce (now I caught it), so I can't just stop the script and start the debugging.
Any help would be really appreciated
P.S. Script logic is hard to understand, so I can't to figure out why it's frozen by power of thoughts.
Try to find the process id (pid) of the shell, you may use ps -ef | grep <script_name>
Let's set this pid in the shell variable $PID.
Find all the child processes of this $PID by:
ps --ppid $PID
You might find one or more (if for example it's stuck in a pipelined series of commands). Repeat this command couple of times. If it doesn't change this means the script is stuck in certain command. In this case, you may attach trace command to the running child process:
sudo strace -p $PID
This will show you what is being executed, either indefinite loop (like reading from a pipe) or waiting on some event that never happens.
In case you find ps --ppid $PID changes, this indicates that your script is advancing but it's stuck somewhere, e.g. local loop in the script. From the changing commands, it can give you a hint where in the script it's looping.

Resources