Mover um processo já em execução para o Screen

206

Meu trabalho de escritório rotineiramente me vê conectado a uma caixa Linux via VNC.

Às vezes, inicio um trabalho remoto no console e percebo depois que ele é executado muito mais do que o esperado. (Deveria ter começado aquele em Tela em primeiro lugar ...)

Eu não quero manter minha estação de trabalho em execução durante a noite apenas para manter a sessão do VNC aberta; Eu gostaria de mover esse trabalho remoto já em execução para uma sessão Screen (na caixa remota), para que eu possa desligar a estação de trabalho (e reconectar na manhã seguinte).

Como isso pode ser feito, se de alguma forma?

    
por DevSolar 18.08.2009 / 11:03

3 respostas

196

Dê uma olhada no reptyr , que faz exatamente isso. A página do github tem todas as informações.

reptyr - A tool for "re-ptying" programs.

reptyr is a utility for taking an existing running program and attaching it to a new terminal. Started a long-running process over ssh, but have to leave and don't want to interrupt it? Just start a screen, use reptyr to grab it, and then kill the ssh session and head on home.

USAGE

reptyr PID

"reptyr PID" will grab the process with id PID and attach it to your current terminal.

After attaching, the process will take input from and write output to the new terminal, including ^C and ^Z. (Unfortunately, if you background it, you will still have to run "bg" or "fg" in the old terminal. This is likely impossible to fix in a reasonable way without patching your shell.)

    
por 28.06.2011 / 09:25
43

Você não pode fazer isso facilmente. Eu sugiro criar o hábito de iniciar a tela como a primeira coisa que você faz depois de abrir um console.

No entanto, para o seu problema real, há outra coisa que você pode tentar: depois de ter lançado o seu trabalho a partir do terminal, faça um plano de fundo digitando ctrl-z e, em seguida, bg . Depois disso, separe o trabalho do shell pai; no bash você faria disown -h %<jobid> . Depois disso, você pode fechar o terminal com segurança e o trabalho continuará em execução.

    
por 18.08.2009 / 11:11
37

Como você está usando o Linux, que tal usar o retty dentro do processo de tela recém-lançado?

$ screen -S my_process
$ retty $(pgrep my_process)
/redraw

HTH

aplausos

    
por 18.08.2009 / 12:09