Multiple choice technology programming languages

9.) How do I `lock' a file?

  1. a) Use filelock()

  2. b) use lockfile()

  3. c) Use lockfd()

  4. d) use fcntl()

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

fcntl() is the POSIX system call used for advisory and mandatory file locking in Unix/Linux systems. It operates on file descriptors and provides mechanisms like shared and exclusive locks through the F_SETLK and F_SETLKW commands. The other options (filelock(), lockfile(), lockfd()) are not standard POSIX system calls.