'How to bring a nohup task to foreground after the shell is closed
I executed the command below in a linux shell:
$ nohup run &
Here run is a blocking command. Then I close the shell and start a new one. However in the new shell I cannot bring the task to foreground via fg, nor can I see it via jobs. Is there still a way to bring it to foreground?
Solution 1:[1]
Use screen instead of nohup:
screen -dmS demo bash -c 'while ! read -t 1;do echo $((i++));done'
Note: there are no &.
Then exit... Later, you could:
screen -x demo
Hit keys Ctrl+a, then d to leave console running
Or
gnome-terminal -e 'screen -x demo'
Then, simply close window to leave process running.
Solution 2:[2]
From what I understand, run is a subprocess of the shell, and when the shell closes, run also closes.
Maybe using tmux or screen can achieve what you want.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Yatogami |
