1

What is the best way to prevent multiple access of a serial port across multiple processes using C\C++ on Linux.

Assuming each process can access the serial port at any time. What is the most efficient way to restrict to only one process can access the a serial port at a time. Once the serial port is in use, I would like other process to be blocked. Once the current process release the port the next process can take over the serial port base on first come first serve rule.

LOK
  • 349
  • 2
  • 4
  • 15
  • Does this work for you? http://stackoverflow.com/questions/17980725/locking-linux-serial-port/17983721#17983721 You can just poll on open in this case. – Mitchell Kline Apr 05 '17 at 04:19
  • @MitchellKline: That takes care of the block, but this question specifies a "first come first serve" access. That requires a queue, which Linux does not provide. – MSalters Apr 05 '17 at 07:24
  • @LOK: are the processes cooperating (all under your control)? Otherwise, things get more complex quite rapidly - a random other process isn't "C/C++" but assembly. And on an unrelated note, there's no such thing as C/C++ anyway. They're two languages that forked at the end of the previous century. – MSalters Apr 05 '17 at 07:27
  • Hi @MSalters yes all the processes are under my control and they will be implemented using C++ and C. And yes MitchellKine solutions did take account of the queuing aspect. And now I am thinking of using cross-process mutex. http://stackoverflow.com/questions/9389730/is-it-possible-to-use-mutex-in-multiprocessing-case-on-linux-unix – LOK Apr 05 '17 at 20:12

0 Answers0