You may have encountered some commands which take a while to complete processing. There are some tricks that could help gain control once you launch the command so that you can do other things meanwhile.
1 – First you can append the sign ‘&’ to the end of command so that it will run in the background as follows:
your_command &
You can hit Ctrl+Z in order to suspend it. To put it in the background, use the ‘bg’ tool:
your-command
[Ctrl+Z]
bg
2 – The command below :
nohup your_command &
Will run the process in background but it also generates a log ( nohup.out in your current directory or in your home directory otherwise).
Furthermore, if you exit your current shell, the process is not killed.
Read: Monitoring system processes in Ubuntu using htop.
3 – Using also disown as shown below :
your_command &
disown
The process here will detach itself from the current shell so that you can carry out other tasks….
4 – Redirection. The command :
your_command > output_file.log 2>&1 &
This will launch the process related to your command and redirect stdout and stderr to a file output.log. In case you do not need the output, you can replace the output file with /dev/null.
Read: How to execute commands in parallel in Linux
The sign ‘&’ if for background processing .
2>&1 is used to redirect stderr to stdout so that the output can be retrieved.
If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.
I’m using a ‘system’ command in a Ruby script and for me the 4th was the only one that worked perfectly:
4 – Redirection. The command :
your_command > output_file.log 2>&1 &
Thank you for the post!