Multiple choice technology programming languages

How do I `lock' a file?

  1. Use filelock()

  2. use lockfile()

  3. Use lockfd()

  4. use fcntl()

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

File locking in Unix/Linux is typically done using fcntl() system call with F_SETLK or F_SETLCK commands. Options A, B, and C refer to non-standard functions. The fcntl() system call is the POSIX-standard method for advisory file locking.