File Control (fcntl)

Function Prototype

int fcntl(int filedes, int cmd, .../* int arg*/);
  • We put the command (flag) we want to execute in cmd section, if the command require extra argument then we put them into arg section

Function

Change the properties of open files


CMD

File Descriptor Duplication

  • F_DUPFD - similar to dup, but we can specify the lowest file descriptor number we want in arg

File Descriptor Flag

  • F_GETFD
  • F_SETFD

管理 open file desc. table 的 flag

File Status Flag

Command

  • F_GETFL
  • F_SETFL

管理 open file table 的 flag

Flag

These flags work with flags belong to open file table

  • O_APPEND- same as that in open
  • O_NONBLOCK - turn open file object to non-blocking
  • O_SYNC - same as that in open
  • O_ASYNC - enables asynchronous I/O notification, the system will send a signal when data become available for read/write

Signal Ownership

  • F_GETOWN
  • F_SETOWN

File Locking

File Lock