Sharing a serial port among multiple processes

I am creating a Daemon in Unix that will have exclusive access to a serial port "/dev/tty01". I am planning to create a Master - Slave process paradigm where there is one master (the daemon) and multiple slaves.
I was thinking of having a structure in "Shared memory" where the slaves can access, and there is only one writer to the memory so I most likely wont need a semaphore. The data will be updated fairly slowly, once every minute for example.
I was looking into what would be the best possible way to do this, also if I have a structure in shared memory, how can I guarantee that the structure will be contiguous in memory? It is a requirement I must have.

The master program will have its own internal data structure that is being updated from the serial port, and then it will modify the data and send it out to a global structure that is in shared memory for the clients to use.

I dont have much experience in Unix IPC, but what would be the easiest way to do this? By the way the clients will all be different processes ran by other users locally on the system

Hi Zacharoni,

Thinking that way is the best premise for troubles. You need to use semaphore, as long as the memory is accessed concurrently by 2 or more processes ( Ok, there are way to come without semaphore. But usually one starts with a semaphore - and only if there are some major performance bottlenecks - one turns to other more complicated synchronization algorithms that are "semaphore free" ),

By "contiguous" in memory, you mean that the structure fields can be accessed linearly from the structure's base address? Unless you have a self-referencing structure (like linked list, tree...), that should work. ( remember though, that the compiler can pad the structure, for instance due to alignment architecture requirements. But that's something you should cope with anyway I guess )

Should the client be aware when the data are updated by the master? Or are the clients reading the data asynchronously (e.g. at some later time) after the update?

Hope this helps,
/Lew

If it must be contiguous in memory, don't break it up into multiple bits. :shrug:

I think you will need a semaphore of some sort because, without any IPC, you're stuck with polling.