Andrew Mercer
on this page

    You started a long job, pressed Ctrl+Z, and now want it to survive logout. Running fg in a new shell fails:

    fg: current: no such job
    

    reptyr re-parents a running process to your current terminal.

    sudo dnf -y install reptyr                     # or apt-get install reptyr
    
    # In a new screen session, adopt the process:
    screen -S adopted reptyr <PID>
    

    Find the PID with pgrep -af name. Often the process must first be stopped and backgrounded in its original shell (Ctrl+Z, bg) so it is not attached to the terminal's foreground group.

    On systems with restricted ptrace (Ubuntu and others), you may need echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope temporarily, or run reptyr as root. Reset it to its previous value afterwards. It does not work for every program (those using multiple terminals or unusual terminal state can misbehave). Next time, start long jobs inside screen or tmux from the beginning.