Advertisement

sending cin to a process

Started by September 18, 2009 01:35 AM
2 comments, last by Katie 15 years, 2 months ago
Hi guys, I'm running a process in the background after closing a terminal session: i.e nohup ./xxxx &. However it has a command line interface which I'd like the user to be able to access when they log in, even though it isn't running in 'focus' any more. Could anyone suggest how I might go about achieving this? Thanks
- Teach a programmer an answer, he can code for a day. Show a programmer the documentation, he can code for a lifetime.
There are several possible solutions here.

If the process you are running is something you have the source code, simply bolt a TCPIP server into the back. You can then "telnet" to it, feed commands to it and have them interpreted in the same way as its command line.


If you don't have the source code, you'll have to do a little more fiddling; basically you start a process you write which launches the other app by opening pipes, forking, closing stdin/stdout, duplicating the pipe endpoints into fds 0 and 1 and then execing the other app. At which point your process now has control over the input/output of the other one.[1]

Then you can do the TCPIP server thing, and be able to telnet in and issue commands at it.

Another option may be to use "screen", which basically does this in a more general way. Have a look at "man screen". Notably it allows you to launch terminal sessions to which you can reconnect later. This might be suitable depending on whether you want just the person who launched it to be able to connect to it.





[1] This (as an aside) is exactly what the shell does to launch an app -- it just connects the app's FDs 0 and 1 (and 2 for errors) to the terminal. There's nothing special going on, this is completely normal UNIX.
Advertisement
Thanks - yes it's an app I'm developing so thankfully I have access to the source code.

I'll take your advice and implement the tcp interface!
- Teach a programmer an answer, he can code for a day. Show a programmer the documentation, he can code for a lifetime.
In that case, may I suggest having a look at "epoll" to use as the centre of it -- it makes managing multiple connections/accepting sockets very easy.

This topic is closed to new replies.

Advertisement