Search code examples
clinuxfile-descriptortty

Open returns identical file-descriptor in different processes


System: Ubuntu 12.04
Compiler: gcc (version: 4.6.3)

My idea is to write a client-server application to exchange data via the serial port.

But my problem is, when I execute the code-snippet below, open returns the same file descriptor if I start two independent processes:

The first process opens "/dev/ttyS0".
The 2nd process opens "dev/ttyS1".

    ....
    serialPortDescriptor = open(portName,
                                O_RDWR | O_NOCTTY | O_NDELAY | O_EXCL);
if (serialPortDescriptor == INVALID_SERIALPORT_DESCRIPTOR) {
    return SERIALPORT_UNKNOWN_ERROR;
}
    .....

Is it normal that open returns the identical file descriptor value for different devices/pathnames ("dev/ttyS1" and "dev/ttyS0" respecively) in two different processes/programs?


Solution

  • It's totally normal. File descriptor is just an offset into in-kernel per-process open file table.