open(), dup(), and close()

The resource manager shared library automatically handles dup() messages.

Suppose that the client program executed code that eventually ended up performing:

fd = open ("/dev/device", O_RDONLY);
fd2 = dup (fd);
fd3 = dup (fd);
close (fd3);
close (fd2);
close (fd);

The client generates an open connect message for the first open(), and then two _IO_DUP messages for the two dup() calls. Then, when the client executes the close() calls, it generates three close messages.

Since the dup() functions generate duplicates of the file descriptors, new context information shouldn't be allocated for each one. When the close messages arrive, because no new context has been allocated for each dup(), no release of the memory by each close message should occur either! (If it did, the first close would wipe out the context.)

The resource manager shared library provides default handlers that keep track of the open(), dup(), and close() messages and perform work only for the last close (i.e., the third io_close message in the example above).