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 need help figuring out how to have 2 programs communicate. what i have going is a program that creates structures, currently this program writes these structures into a file. then i have a second program that reads that file. that works all well and good, but the structure genereating program is just a temporary piece in the larger puzzle, eventually what is gonna happen is that structures are going to be written to that file in somewhat real time. now i cant decide if i should scan this file continuously, look for the end, and then read the last structure, which seems like a huge hasle. im sure there is a better method that i just dont know about, can anyone help?
You might try looking at named pipes; see the popen and pclose manpages.
Basically, a named pipe is a special file that can only be written to if another process has the file open for reading. Instead of writing to the file, the data is held in memory, and can be read by the other process (streaming).
There are other forms of IPC (interprocess communication) available; loopback network sockets tend to be the first choice thesedays, but shared memory is still around as well. Try googling these terms.
Quoting "rjlee":
You might try looking at named pipes; see the popen and pclose manpages.
While named pipes may be an option, popen() and pclose() are about normal unnamed pipes, not named pipes. Check "man 4 fifo" (and the man pages referenced in the "see also" section) about named pipes.
If it is about one process writing data to another single process, only in one direction. (i.e. process A writes to process B, and process B does not write back to process A): Use a "name pipe" (also called "filesystem pipe" or "fifo"). This is the most easy option, with the least possibilities.
If there's more than one process that needs to read, or if there the reading process need to "talk back", but exchanging data across a network is not needed, use "filesystem sockets", IPC message queue's or IPC shared memory. I suppose filesystem sockets are the easiest, because you don't need signalling, semaphores...
If you need to pass the the data over a network, use TCP (or maybe UDP) sockets. Also when you think this may be needed in the future, use these network sockets, and use the loopback interface (IP-address 127.0.0.1) when connecting to the same machine.
To add to what Hko wrote you have also a possibility to use local sockets (or Unix domain sockets) designed to work between programs on the same machine.
thanks for the help guys, now i really have some options to look into, just to give a lil more background info on my question, im writing telemetry software for my school's solar car, right now the car's internal telemetry system that brodcasts the information to the chase car, is under construdtion, so i have a program that is simulating the packets, by creating fake structures, currently those are written to a file, which will stay that way in the final version, for reference if we need it, but what also needs to happen is that a gui needs to read these structures and make graphs charts and what not. im gonna look into the options you guys gave me tonight hopefully, thanks for the help, and if you guys have any other suggestions, im all ears
Will it use a kind of network to communicate? If so, use sockets. When the real program is ready, you'll just need to change the type of socket and the whole code should just work.
yah, when everything is said and done it should be using a serial modem, but the crew is tossing around the idea of 802.11, but so far it looks like we are gonna stick to the radio modem
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.