DEV Community

Discussion on: How to keep a process running even after closing SSH connection?

Collapse
 
loki profile image
Loki Le DEV

There is also the nohup command

Collapse
 
email2vimalraj profile image
Vimalraj Selvam

I highly recommend this command, we use this on daily basis instead of 3rd party tools.

Collapse
 
bobbyiliev profile image
Bobby

Thanks for sharing Loik! I’ll definitely check it out!

Collapse
 
krishnanunnir profile image
Krishnanunni R

If I may ask how do you handle killing the process?

Collapse
 
aderchox profile image
aderchox

Here's my note on this for you:

===== Listing Processes =====
List processes owned by the current user (sorted by PID, from PID 1 to higher/user-level PIDs)
ps
List all processes, including system processes
ps ax
List all active processes, including system processes, with extra information like RAM/CPU usage, owner user, etc.
ps aux
Human-readable shiny process list, with features like search, filtering, tree structure, realtime resources usage monitor, etc.
htop

===== Killing Processes (kill vs. killall vs. pkill) =====
Kill a process by its id
kill <process_id>
Or use killall with the process name (Can be risky if multiple processes share the same name)
killall node
Or use pkill with the process name or other attributes (The most versatile of the three commands, allows terminating processes by name, exact match, or pattern matching using regular expressions) (Can be risky if the pattern matches unintended processes)
pkill

Killing without mercy
kill -9 <process_id>
Killing by giving the stuck process a chance to clean up before dying (RECOMMENDED)
kill -15 <process_id>

Collapse
 
loki profile image
Loki Le DEV

Just be careful because by default it opens a nohup.out file and appends all output of the process you launched into this file. It can grow a lot.

Collapse
 
bayindirh profile image
Hakan Bayındır

If you're afraid of filling your disk, just toss the output to /dev/null during the command invocation ;)

Collapse
 
drewmullen profile image
drewmullen

This is my go-to

nohup command ... &