How to get data from serial port?

   I am using Sun Solaris 2.6,and C compiler on Solaris.
   I got new project in which i need to acceess the serial port i.e i will be getting the data through modem (leased line modem) and my program need to read the data comming through serial port and depending upon the incomming data i need to process that data and if required put that data in the database.
   I know that unix treat device as the file and in solaris "/dev/ttya" and "/dev/ttyb" are the two files which represents two serial port and in c with the file read and write operation i can achieve the reading and writting on the serial port,but i don't know how the incomming data is stored in the file(/dev/ttya or /dev/ttyb) whether these file gets overwritten each time new data commes or all the serial port data get appended in the file and get deleted after end of the session. what really happens ?
Please advice.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

rbrConnect With a Mentor Commented:
It looks like a file but it is more like a pipe. (FIFO). In unix you have the possibility to write a driver that simulates a file (the os-driver for ttyx is such a programm) The file does not exist anywhere in the fs only the driver must handle some basic fuctions. If you want to access such files you can open them like real files and read and write on it (If the driver supports reading and writing) The data comes in a stream and will not be overwritten if new data comes. The data will be but on a queue. The only problem you can have that the internal buffer of the driver will be full. Then it depends on the driver if the device will be blocked or the old data will be overwritten by the new one.
All Courses

From novice to tech pro — start learning today.