Sharing a serial port among multiple processes


 
Thread Tools Search this Thread
Top Forums Programming Sharing a serial port among multiple processes
# 1  
Old 09-24-2011
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
# 2  
Old 09-26-2011
Hi Zacharoni,

Quote:
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.
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" ),

Quote:
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.
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 )

Quote:
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.
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
# 3  
Old 09-26-2011
Quote:
Originally Posted by zacharoni16
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.
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Cabling and adapters to communicate to service processor serial port from Windows PC with USB port.

Hello, I have an unloaded T5140 machine and want to access the ILOM for the first time and subsequently the network port after that., and then load Solaris 10 the final January 2011 build. The first part is what confuses me -the cabling. I am coming from a Windows machine (w/appropriate... (5 Replies)
Discussion started by: joboy
5 Replies

2. UNIX for Advanced & Expert Users

Asynchronus resource sharing between processes?

Hi, say I have some pages which I want to share between two processes asynchronously. Which IPC (inter process communication) mechanism is best for this kind of job to complete? Is the same mechanism work for synchronous sharing? Thanks for the replies. sanzee (2 Replies)
Discussion started by: sanzee007
2 Replies

3. Solaris

How to enable Serial port on ILOM, when Network Port is enabled in parallel

Hi Everyone, In my environment, I have few T5220. On the iLOM Management Card, I have both Network and Serial port are cabled, I don't have any issues while I try to connect using Network Management port, but when I try to connect the serial port for the same server which is actually connected... (3 Replies)
Discussion started by: bobby320
3 Replies

4. Shell Programming and Scripting

Need help with serial port

Hi, I have a external board connected to my serial port. I need to execute "shutdown -r now" command when system boot up. When system boots up it requires a username ans password. Then I need to run my command. I can use rc script but that is rebooting system before it asks for username and... (0 Replies)
Discussion started by: charlie.arya
0 Replies

5. IP Networking

SSH Port Forwarding - sharing the same port

Hi Linux/Unix Guru, I am setting Linux Hopping Station to another different servers. My current config to connect to another servers is using different port to connect. e.g ssh -D 1080 -p 22 username@server1.com ssh -D 1081 -p 22 username@server2.com Now what I would like to have... (3 Replies)
Discussion started by: regmaster
3 Replies

6. OS X (Apple)

Serial port parameters

Hello, I am trying to use a rs232 device through a USB serial port on my MacBook pro laptop. I think the device needs the communication parameters to be 9600 n 8 1 my question is does anyone know what the default communication parameters are for mac os x 10.5.7 unix? And if the default... (0 Replies)
Discussion started by: jamesapp
0 Replies

7. Solaris

Serial port not found

Hi, I am working with solaris 9,SUN-Blade-100 and I want to communicate with the Serial port.To check whether the port is working or not.I write code and when I execute the file,then I got the output-- According to this,serial port is not found.can anyone please tell me how to configure the... (1 Reply)
Discussion started by: smartgupta
1 Replies

8. Filesystems, Disks and Memory

Processes sharing.......

What are the differences in processes sharing variables, memory pages or files? Is one safer than another? (1 Reply)
Discussion started by: MS_CC
1 Replies

9. IP Networking

Routing, Port Mapping, Internet Sharing etc etc

I'm running OS X. (OS X Server actually) and right now I use a program called BrickHouse to handle my router configuration. But this program kind of sucks. I'd much rather learn how to configure these programs manually. By these programs, I mean the programs OS X comes with to handle these jobs... (0 Replies)
Discussion started by: l008com
0 Replies

10. UNIX for Dummies Questions & Answers

Serial port communication

We're running SCO Unix Openserver 5.05 and I'm having trouble with serial communication between the com2 serial port and a handheld device. Downloading data from Unix to the handheld works perfectly, but the other way around creates a major problem. I don't know whether it's a buffer overflow or... (1 Reply)
Discussion started by: Aretha
1 Replies
Login or Register to Ask a Question