ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm trying to do an application that converts applications into daemons (more or less). I basically have several programs (around 10) that are basically console programs with a menu. For example if you press 's' the program will give you statistics. Now I have to run all the programs simultaneously. I would like to have all the programs running as daemons but if I require to "connect" to the programs then I can (maybe by process Id or some other identifier) pipe the current cosole to the specific daemon, as if I'm running that program in the current console. Then I close that connection and I connect to another daemon. I know I can program that into each one of the programs, but I would rather not. I would like not to modifiy the programs at all but have a main program that does something like a popen to each process and then I can redirect those pipes to a console. Somebody knows how can I do that?
Run them is screen sessions. Then you can connect/disconnect/reconnect to them arbitrarily. If you make screen multi-user, you can allow anyone to connect, or a specified selection of users to access the 'daemons'.
are they persistent, like overnight, or just while you are logged in and playing with them?
ok, each daemon process starts off and makes a FIFO or named pipe or Unix domain socket,
based on pid, these live in a certain directory, your selector program then can scan the directory
and allow you to choose which process to pipe to.
easy
I'm doing something like that right now. I have this program that creates one thread for each daemon that I have to run. Then I create two pipes and then close(0 and 1) dup2 fork execve. After that each thread creates two named fifos and then they enter in a loop that reads from one of the named fifos and copies into the pipe corresponding to stdin and viceversa. As long as I catch the SIGPIPE signal and I check for the errors it works, but I think is too complicated, I was looking something more obvious like going into /proc/fd and try to replace the symlinks to 0,1,2 (already tried but couldn't make it work). Then I started looking at the source of screen and dtach (similar to screen but simpler) and they basically do something like what I do but using a lot of PTY (that I'm not very familiar with).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.