TL;DR How can I get a bg
(background) job into fg
(foreground) after I close the terminal window?
FULL I'm using terminal to start Spotify and put it into background with CTRL+Z
and bg
. Everything works as expected within this window: fg
puts the process again in forground and jobs
shows me Spotify as a running process. The problem occurs if I close the terminal window.
After I close the terminal window and open a new terminal window, the jobs
command can't find Spotify running in the background. Therefore I can't access the process for stopping or closing anymore.
What is the advantage of this behaviour CTRL+Z
, fg
, bg
& jobs
? And how can I get back my process?
You can search your old process via ps -A
. Or ps -A | grep <application name>
.
If you found it, then use reptyr <pid>
to get the application on your new console.
But if you closed the old terminal, all the terminal applications will probably be closed also, so it's too late.
Use screen, before you start your app. This will help you to reconnect to your session from another terminal.
The job numbers only refer to background processes running under your current shell. The shell couldn't know the job numbers associated with the old shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With