1

I am running a simulation command in a server using ssh, from my terminal.

The simulation is running for 10+ hours. I am expecting output after 15+ hours.

During its execution it was echoing on the terminal some random results. What is important to me is the end results that it will generate during last 30 mins. of the simulation before it ends.

I lost Internet connection so my ssh broke, but then when I again connected to ssh, I checked that my program was still running in the remote server.

  PID TTY          TIME CMD
 2063 ?        00:00:00 sshd
 2064 pts/14   00:00:00 bash
 2156 pts/14   01:19:14 sim-cache
15446 ?        00:00:00 sshd
15448 pts/30   00:00:00 bash
15593 pts/30   00:00:03 sim-cache
15636 ?        00:00:00 sshd
15637 pts/31   00:00:00 bash
15652 pts/31   00:00:00 ps

But since it is running in background I will never see its output.

Can someone tell me how can I bring the running process into current terminal, so that whatever this process echoes here after I can see that in the terminal?

migrated from stackoverflow.com Nov 23 '15 at 0:44

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

  • 1
    This question should have been asked in Linux and Unix Stack Exchange since there is really no coding help involved here. Although, I did answer it below. ;-) – Munir Nov 17 '15 at 3:53
1

fg command does that. Here's a link or use man fg for help.

0

The solution is to start the simulation in screen that allows disconnecting and attaching from terminals. You can even attach from multiple terminals same time to see output from multiple computers same time.

0

While it will not help you with the instance that is already running, you can redirect the output of your program to a log file as in this answer to a related question:

sim-cache > logfile < /dev/null 2>&1 &

This way, you will have the output regardless of whether you can reconnect to the process before it completes or not.

For the time being, use fg 2156 to bring the process to the foreground in your shell, where 2156 is the PID of sim-cache from the listing you gave.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.