title: Locking Linux Serial Port
body: <p>I have an issue that I'm trying to solve regarding the serial port in Linux.  I'm able to open, read from, and close the port just fine.  However, I want to ensure that I am the only person reading/writing from the port at any given time.</p>
  
  <p>I thought that this was already done for me after I make the open() function call.  However, I am able to call open() multiple times on the same port in my program.  I can also have two threads which are both reading from the same port simultaneously.</p>
  
  <p>I tried fixing this issue with flock() and I still had the same problem.  Is it because both systems calls are coming from the same pid, even though there are different file descriptors involved with each set of opens and reads?  For the record, both open() calls do return a valid file descriptor.</p>
  
  <p>As a result, I'm wondering if there's any way that I can remedy by problem.  From my program's perspective, it's not a big deal if two calls to open() are successful on the same port since the programmer should be aware of the hilarity that they are causing.  However, I just want to be sure that when I open a port, that I am the only process with access to it.</p>
  
  <p>Thanks for the help. </p>