Linux - process communication? reunite the process in action?
I feel a bit silly asking this, but I'm relatively new to Linux (more in terms of experience than time) and one thing I've always thought about is if I can "rejoin" (my own term) the process while it works.
For example, if I have installed a game server or eggdrop IRC bot in the background, is there a command I can use to watch this process in action and see all the output it delivers to the console?
I'm not talking about just viewing the process using the "top" command, but actually referring to it as if I were just running it from the command line.
Thanks.
a source to share
Can you be more specific? You just talk about the origin of the process in the current session and then bring it back to the foreground.
eg:.
doLongTask &
# Later
fg %3
3 in this example is the job number of this doLongTask instance. You can view all current assignments with:
jobs
But note that this will still allow you to see what is being output to the console. I.E. stdout and stderr, minus any redirects.
a source to share
Simple answer:
>> ./runmyserver
<press ctrl-z>
>> bg
>> ...do something else ...
>> fg
You can also start in the background with:
>> ./runmyserver &
For more complex things like disconnecting the server from the console session (so it still works when you log out), you really need a screen. Maybe ask them about it, this is not a security threat and it is a useful program.
Also note that ctrl-z actually pauses your server until bg
, so if people are playing on it, maybe skip a beat, it's best to do it quickly.
Finally, many game servers have a remote login for this kind of thing that would resolve many of these issues. Make sure your game and host don't support this before looking for alternatives.
EDIT: re-read your question. It looks like you could get the output using a file redirect. This will prevent you from adding more input:
./runmyserver > log.txt
a source to share
If you know ahead of time you want to do this, use screen (1) and start your server in the foreground in a screen session. You will be able to disconnect from the screen session and continue working. You can then reconnect the screen session and view any output it has made since then, up to the size of the scroll buffer.
a source to share