Linux

How to run Linux command in background? How to keep it running after leaving terminal session?

When working with remote server through terminal it is common to run some processes in background. For example to start zipping something, put it into background and keep working on something else. Or even start a process and leave it running when you quit a terminal session. A quite common example could be – start application server. You just need it up and running even if you terminate your terminal window. Leveraging couple of linux features will help as here:

Push any command you run into background. Keep working with terminal while it is running. Append “&” at the end of the command. Example:

$./startWeblogic.sh &

Afterwards you can just click “^ + c” (macOS terminal) and keep working on other task in remote system. To check what tasks you have put in background, execute:

$jobs

And finally if you want to leave those processes running even if you leave terminal session, need to disown them. Here is a straight forward command to accomplish this:

$disown

Red Hat Enterprise Linux 7.4


Advertisement

Leave a Reply

Your email address will not be published.