Reputation: 655
I wrote an interactive Unix program that runs on a terminal. Sometimes, I leave it running and then go home, but then I cannot interact with the running process through ssh.
There are solutions to this like using Gnu screen etc., but how hard is it to build this functionality into my program? For instance, say my program is called “prog”, and say it is running in a terminal. Now imagine I log in through ssh. I would like to write something like
$ prog move
or so in the command line and have the running program transfer itself to the ssh session terminal. This should be possible, but is it hard to do?
Upvotes: 0
Views: 65
Reputation: 41474
It's fairly straightforward to detach (see the daemon
function). Reattaching is more of a pain, basically consisting of routing input and output through a named socket, and having a second invocation act as a relay for that socket. But in general, this is a silly thing to build into a program, because it's not what the program is otherwise for. It's like building an email client into your text editor, just in case someone wants to check their email while editing something.
If screen
is too heavyweight for your needs, try the dtach
program, which was designed to be wrapped around a single application (and works well in shell scripts). If you must shove this up inside your application, the best approach would probably be to incorporate source from dtach
.
Upvotes: 2
Reputation: 1093
Write your program in 2 parts.
The first part is a system that runs continuously, which looks into a file, or a pipe.
The seconds is a command line program, which writes to the pipe.
Upvotes: 0