what's the purpose of fcntl with parameter F_DUPFD

Posted by Daniel on Stack Overflow See other posts from Stack Overflow or by Daniel
Published on 2010-04-12T03:14:46Z Indexed on 2010/04/12 3:23 UTC
Read the original article Hit count: 280

Filed under:

I traced an oracle process, and find it first open a file /etc/netconfig as file handle 11, and then duplicate it as 256 by calling fcntl with parameter F_DUPFD, and then close the original file handle 11. Later it read using file handle 256. So what's the point to duplicate the file handle? Why not just work on the original file handle?

12931: 0.0006 open("/etc/netconfig", O_RDONLY|O_LARGEFILE) = 11

12931: 0.0002 fcntl(11, F_DUPFD, 0x00000100) = 256

12931: 0.0001 close(11) = 0

12931: 0.0002 read(256, " # p r a g m a i d e n".., 1024) = 1024

12931: 0.0003 read(256, " t s t p i _ c".., 1024) = 215

12931: 0.0002 read(256, 0x106957054, 1024) = 0

12931: 0.0001 lseek(256, 0, SEEK_SET) = 0

12931: 0.0002 read(256, " # p r a g m a i d e n".., 1024) = 1024

12931: 0.0003 read(256, " t s t p i _ c".., 1024) = 215

12931: 0.0003 read(256, 0x106957054, 1024) = 0

12931: 0.0001 close(256) = 0

© Stack Overflow or respective owner

Related posts about fcntl