How to run a command, process or script in the background on a server

It is a very common need to run a command or process in a server in the background. This is especially true when you are running the command over a SSH connection, since the connection can be dropped due to multitude of reasons, it’s always better to run that command in the background.

The command is very simple, you just need to append an ampersand symbol at the end of the command, the syntax is given below

$ the-command -with -options to execute &

for example, you want to run a long running python or php script, and the file name is ``

$ python3 &

now you will see an output similar to the following in the terminal

[1] 3920

this means that the job number for your background job is 1, So when you want to bring this to the foreground use the fg command

fg %1

now this will bring the job number 1 to the foreground so that you can interact with it.

when you want to see all the jobs running in the background, use the jobs utility this will list out all the background jobs that.

Programmer, Hacker, Trainor, Speaker, and Blogger. Opensource Lover. Built

Leave a reply:

Your email address will not be published.

Site Footer