I started a process on my Linux machine through Putty by running a jar. Now the program will take at least 24 hours to run, and my Putty terminal session has been interrupted. I have added code in the program to output information to track the progress of the job via System.out.println. If I know the PID of the process, is there any way to open a new terminal session in Putty and view the output the process is currently outputting, as if I were in the same session from which I executed the JAR?


migrated from stackoverflow.com Aug 27 '12 at 1:00

This question came from our site for professional and enthusiast programmers.

  • For future reference, I would just redirect the output to a text file for something like this. – squiguy Aug 26 '12 at 0:56
  • strace -p PID would be a crude way to find out what it's currently printing. For future reference... run screen when you log in via ssh, then if you get disconnected you can log in and run screen -r to pick up where you left off. – Alan Curry Aug 26 '12 at 1:05

You can attach your process to a new terminal like this:

git clone https://github.com/nelhage/reptyr.git
cd reptyr/

And grep for you JAR PID:

ps -ef | grep "YOUR_JAR"

Then :

./reptyr YOUR_JAR_PID

And you'll see that the current session will be attached to your JAR.

More on this great tool : http://blog.nelhage.com/2011/01/reptyr-attach-a-running-process-to-a-new-terminal/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy