0

Say you have a script that takes a while to do something, but then later requires some user input e.g. something like:

#!/usr/bin/python -u
import time
x=0
while(x<10):
    time.sleep(1)
    x+=1
    print(x)
print(input())

and you wanted to run this process in the background and then later recall it in another terminal window, perhaps using

./script.py > output.txt & disown

This process is no longer listed under jobs, but you can see it is still running with pgrep script.py (because you disowned it). Thus you can't recall this job with fg . Is there a way to re-own the process and/or bring it to the foreground in another terminal window? This would be particularly useful when you are controlling the machine remotely with ssh and are worried about an unstable connection.

5
  • 1
    That’s a problem commonly solved by using a terminal multiplexer like screen or tmux, see the linked questions.
    – dessert
    Feb 12, 2020 at 8:52
  • This is not a duplicate of the articles provided. Screen/tmux are not solutions to the problem in the OP. I have made my last sentence boldface to illustrate my point. The point is can you start a process, disown it, close the terminal, and access it again in another terminal, e.g. if it crashes or ssh disconnects Feb 12, 2020 at 17:55
  • A parent can inherit jobs, so maybe spawn another term, start your process, background it, then when you want, fg it in the parent.
    – ubfan1
    Feb 12, 2020 at 18:04
  • 2
    The tools like as screen and tmux are designed exactly for such purposes! However, here is one interesting article: DigitalOcean: How To Use Bash's Job Control to Manage Foreground and Background Processes And another possible duplication: Keep running a python program even after logging-off the ssh session.
    – pa4080
    Feb 12, 2020 at 18:41
  • @T.ZackCrawford If this question is not a duplicate as specified, explain why in comments or in your question and then ask for it to be reopened. Justification of why it's not a duplicate is needed first.
    – Thomas Ward
    Feb 18, 2020 at 23:31

0

Browse other questions tagged .