I am trying to figure out how to switch to another process, without interrupting the current one. And how then to return to the current. thank

    2 answers 2

    screen to help you. We start screen , in the opened session we start the necessary process. Press ctrl + a, d to disconnect from the session where the process is running. To switch back to the screen session, type screen -r <Π½ΠΎΠΌΠ΅Ρ€ сСссии screen> get to where you left the running process.
    If the session is no longer needed, then, while in the session, press ctrl + a, k and respond positively to the proposal to log the session.

    In this way, it is also convenient to use when unstable ssh connection.

      jobs , fg , bg - background process management

      To run the task in the background, add the & sign at the end of the command, or start it in normal mode, then press the ctrl + Z combination, sending the TSTR signal to it. To continue its execution in the background, use the bg (background) command.

      You can display a list of current background tasks with the jobs command.

      To remove a task from the background mode - the fg (foreground) command is used, to which you can either pass the task number as an argument.

      For example:

       $ tar cpf somefile.tar somefolder 2>/dev/null # запускаСм tar ^Z # Π½Π°ΠΆΠΈΠΌΠ°Π΅ΠΌ Ctrl+Z [1]+ Stopped tar cpf somefile.tar somefolder 2>/dev/null $ jobs # Π‘ΠΌΠΎΡ‚Ρ€ΠΈΠΌ список Π·Π°Π΄Π°Ρ‡ [1]+ Stopped tar cpf somefile.tar somefolder 2>/dev/null $ bg 1 # ΠŸΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠ°Π΅ΠΌ Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ ΠΏΠ΅Ρ€Π²ΠΎΠΉ Π·Π°Π΄Π°Ρ‡ΠΈ Π² Ρ„ΠΎΠ½Π΅ [1]+ tar cpf somefile.tar somefolder 2>/dev/null $ fg 1 # Π’Ρ‹Π²ΠΎΠ΄ΠΈΠΌ Π·Π°Π΄Π°Ρ‡Ρƒ Π½Π° ΠΏΠ΅Ρ€Π΅Π΄Π½ΠΈΠΉ ΠΏΠ»Π°Π½ 
      • Thanks for the tip, really convenient. But this method has one drawback, if you act in this way, the process led to bg is actually paused (as indicated by the message "Stopped") and resumes work only when switching to fg. For man, more than ideal, but if this process should do something in the background, then it does not work. - Andrey
      • After Ctrl + Z, the process can be restarted using the fg command in the foreground or the bg command in the background. After running the bg command, you will see the message "Runing", not "Stopped". - UserTest013
      • Yes, exactly, but if this process has to output something to stdout, then it looks very curious))) - Andrey