How to run a Linux command in background ?


Running a command in the background can be useful when the command will run for a long time and does not need supervision. It leaves the screen free so you can use it for other work. In addition, it doesn’t stop the next processes or commands in queue which doesn’t depend on previous command’s result.

Running a wget command in background

wget -bqc


  • -b : Go to background immediately after startup. If no output file is specified via the -o, output is redirected to wget-log.
  • -q : Turn off Wget’s output (saves some disk space)
  • -c : Resume broken download i.e. continue getting a partially-downloaded file. This is useful when you want to finish up a download started by a previous instance of Wget, or by another program.



function __callURL($url){

function __callURLinBackground($url){
  exec("wget -bqc ".$url);
  echo 'Running in background';

//call a URL normally

//call a URL in background



$contents = file_get_contents('');
file_put_contents('html.html', $contents);

In the above example, we have used sleep() PHP function.

sleep(10) will make the PHP script sleep for 10 seconds. We used this in order to verify that when we call this PHP script in background, the execution doesn’t wait for these 10 seconds and everything will be executed in background however long it may take for the execution.

Alternative Method

We can use nohup like this :

nohup wget &

Follow this video for complete guidance :

ALSO READ  Responsive FileManager as Standalone File Manager

Comments are closed.