AFAIK there's no direct way to foreground a process that was started and backgrounded in another shell. There are a couple of ways to get around this, however.
The best way is to use GNU screen. Start a screen session, start your process, detach from the screen session, log out, log back in, reattach to the screen session. The process is still running and screen keeps any output in the window buffers. You don't even need to background it; you can leave it running in one screen window and use others for other tasks.
The ugly hackish way is to detach it from the terminal before logging out. In bash,
disown -h %[jobid] does this; other shells like tcsh do this automatically for background processes when you exit the shell. (Get the
$[jobid] by running the command
jobs.) You can't reattach to the process directly, but if all you need is a process's stdout/stderr/stdin, you can use GDB to fake the reattaching. This is a partial how-to from this source (originally included in another answer):
[...] with some dirty hacks, it is not
impossible to reopen a process'
So you could still create a blank
screen window (for instance that runs
And then use gdb for instance to
attach to the process, do some
call open("/dev/pts/xx", ...)
The process' output would go to
screen. It wouldn't be attached to
that screen terminal, so for instance[sic]
would kill the "sleep" command, not
the process, but that could be enough
for the OP.
There are some ways of making bash do automatic disowns, but they involve shopts or nohup or other bash tricks to avoid the automatic SIGHUP. bash isn't as graceful as tcsh in this area, and you have to know ahead of time that you'll need this to setup the option. It's a little easier to remember to run disown on your background job before exiting.