This is based on this answer which has instructions for sending output to
To send output of a running program to
/tmp/file.log, for example, do the following:
From a second terminal, use
ps to get the process ID of your program.
touch /tmp/file.log to create an empty file for your output to go into.
gdb -p [PID] using the process ID from
(gdb) prompt type these commands:
In response to the
dup2 commands, you should see "
$1 = 1" and "
$2 = 2". You should see output cease on the other terminal and you should be able to
tail -f the log file (or use
ls -l repeatedly and see the size increase).
Now you can suspend your process using Ctrl-Z and resume it in the background using
bg 1 (or whatever the job number happens to be).