This post will cover how to
start running a programme in a terminal’s background
monitor the programme and
stop the programme
I decided to write this post beacuse I did not find any comprehensive tutorial to cover this aspect.
start running a programme in a terminal’s background To do so, simply add
&at the end of the line. What occurs after the enter is hit is that the first line will be run at the background and the terminal will prompt you another line of input.
monitor the programme When the programme is run in the background, you can check its status by enter
jobs. Usually it will show either
Done. If there is no current jobs and the you have seen all the status of jobs that are done, jobs will give no output.
stop the programme You will see a job ID when you run jobs. To kill that specific job (say its ID is 3), use
Standard stream: Even after you have directed the output of the programme using
>, many programmes are designed to prompt you the error or just the progress of the programme using standard error. This may be distracting because even after you have run the programme in the background and continue to typing other commands, the standard errors will be printed to the screen, sometimes to the line where you are typing. To stop this and only view all the errors when you want to, use
2>to redirect the standard errors to a new file.
Server If you are using a server, you can use
nohupat the start of the command so that even if the connection between your local machine and the server breaks down, the programme will still be running.
Not-so-pro Tip: to test on how to run a background task, you can install a programme called
sudo apt install yes. This is a programme that continously outputs y to your terminal and can be used to give confirmation to other programmes (e.g. when installing other software).
be cautious when you save the command (
yes) output to a file. I tried to run it for around 20 seconds and the file size became 16GB…