Question

What are the implications/caveats that I would need to watch out for if I were to use the Linux environment variables as a simple way of sharing information between different processes (written in Python)? For example, are reads and writes atomic on a single-processor/core system?

I'm designing an embedded system on a Raspberry Pi where I'll have multiple independent processes performing monitoring and control. These processes would sometimes need access to a shared "property" that will be updated by another process. For example, one process might monitor an RFID reader and update an environment variable with the serial number of the last card swiped. Other processes would then be able to access that serial number and use it.

Only reason why I'm considering this idea is simplicity. I'm only interested in sharing simple strings and numbers between processes, and I feel that this is simpler than using something like sockets.

Was it helpful?

Solution

I am working on an embedded system on a RPI also, with similar requirements for certain cases. The best approach from my experience is to use Linux named pipes (FIFOs).

Here are some resources, but there are many more online ofcourse:

http://www.linuxjournal.com/article/2156
http://www.roman10.net/named-pipe-in-linux-with-a-python-example/
http://tuxthink.blogspot.com/2012/02/inter-process-communication-using-named.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top