Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
15
rated 0 times [  15] [ 0]  / answers: 1 / hits: 14529  / 3 Years ago, sat, may 8, 2021, 8:44:30

I know that I can run an application in the background by putting an ampersand (&) at the end of the command. For instance:



$ rtorrent &
[1] 4618


starts rtorrent in the background.



I'd like to return to the backgrounded rtorrent to check whether my downloads are completed. How can I do that?


More From » bash

 Answers
7

Run fg to put the job back onto the foreground, i.e. give it back control of the terminal. If there are multiple background jobs, run jobs to see a list and fg %1, fg %2, etc., to select which job to put back to the foreground.
See the Wikipedia article on job control for more information.



If a program is running on the foreground, press Ctrl+Z to suspend it. When you do this, you'll get a shell prompt. Run bg to make the program keep running, but in the background.



If a background job terminates, the shell will print a notification the next time it displays a prompt. If a background job requires input from the terminal, it will automatically be suspended (“stopped”); fg (or fg %42 if necessary) resumes it.



If you want to trigger a more visible notification when the program finishes, you can run something like



fg; play bell.ogg & xmessage "torrents downloaded"


The fg command returns when the program that it resumes finishes, so whatever you told the shell to run after fg will run when the program finishes. Note that if you press Ctrl+Z to put the job back into the background, then the shell stops waiting and runs the following commands immediately.


[#34700] Sunday, May 9, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
fulpu

Total Points: 116
Total Questions: 118
Total Answers: 104

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
fulpu questions
Fri, Apr 1, 22, 08:36, 2 Years ago
Wed, Mar 16, 22, 15:25, 2 Years ago
Wed, Aug 24, 22, 22:59, 2 Years ago
Tue, Dec 20, 22, 22:33, 1 Year ago
;