views:

131

answers:

4

I feel somewhat dumb asking this, but I'm relatively new to linux (more in terms of experience than time), and one thing that i've always wondered is if I can 'rejoin' (my own term) a process while it's running.

For example, if I set a game server or eggdrop IRC bot to run in the background, is there a command I can use to view that process in action and view all the output it delivers to the console?

I'm not talking about just viewing the process using the 'top' command, but actually linking to it as if I just ran it from the command line.

Thanks.

+5  A: 

Debuggers can "attach" to running processes, but you might be better running your program in screen (which lets you detach and reattach to terminal in a fairly natural way).


There might be some good stuff good stuff in :

dmckee
Lucky me, screen is disabled by my provider :)
scrot
+1 for screen. Screen lets you attach to the same term/multiple sets of terms in the same session.
JensenDied
+2  A: 

Can you be more specific? Are you just talking about backgrounding a process in the current session, then putting it back in the foreground.

E.g.:

doLongTask &

# Later

fg %3

3 in this example is the job number of this instance of doLongTask. You can see all running jobs with:

jobs

But note this will still only let you see what's being outputted to the console. I.E. stdout and stderr, minus any redirections.

Matthew Flaschen
+2  A: 

The simple answer is:

>> ./runmyserver
<press ctrl-z>
>> bg
>> ...do something else ...
>> fg

You can also start in the background with:

>> ./runmyserver &

For more complicated stuff like disconnecting the server from your console session (so it's still running when you log out) you really want screen. Maybe beg them for it, it isn't really a security risk and it's a useful program to have around.

Also note that ctrl-z will actually pause your server until bg so if people are playing on it might skip a beat, best to do it quickly.

Finally, many game servers have a remote login for this kind of thing which would solve many of these issues. Make sure your game and host don't support this before looking for alternatives.

EDIT: Re-read your question. It sounds like you could at least get the output using redirect to a file. This won't let you add more input though:

./runmyserver > log.txt
SpliFF
A: 

If you know ahead of time that you want to do this, use screen(1) and run your server in the foreground in a screen session. You will be able to detach from your screen session and have the process keep running. You can then later re-attach your screen session and view any output it has made since, up to the size of the scrollback buffer.

camh