ftok(3)

ftok3

Create ipc identifier from path name

Usage

#include <sys/ipc.h>

key_t

ftok(const char *path, int id);

Library

Standard C Library (libc, -lc)

Overview

The ftok() function attempts to create a unique key suitable for use with the msgget(2), semget(2) and shmget(2) functions given the path of an existing file and a user-selectable id.

The specified path must specify an existing file that is accessible to the calling process or the call will fail. Also, note that links to files will return the same key, given the same id.

Return values

The ftok() function will return -1 if path does not exist or if it cannot be accessed by the calling process.

Releases

87 releases since FreeBSD 2.0.5-RELEASE; the text changed 47 times.

  1. 2.0.5
  2. 2.1.5–2.1.7.1
  3. 2.2.2–2.2.5
  4. 2.2.6
  5. 2.2.7–2.2.8
  6. 2.2.9
  7. 3.0–3.2
  8. 3.3–3.4
  9. 3.5–3.5.1
  10. 4.0
  11. 4.1–4.4
  12. 4.5–4.8
  13. 4.9–4.11
  14. 5.0–5.2.1
  15. 5.3–6.3
  16. 6.4
  17. 7.0
  18. 7.1
  19. 7.2
  20. 7.3
  21. 7.4
  22. 8.0
  23. 8.1
  24. 8.2
  25. 8.3
  26. 8.4
  27. 9.0
  28. 9.1
  29. 9.2
  30. 9.3
  31. 10.0
  32. 10.1
  33. 10.2
  34. 10.3
  35. 10.4
  36. 11.0
  37. 11.1
  38. 11.2
  39. 11.3
  40. 11.4
  41. 12.0
  42. 12.1
  43. 12.2
  44. 12.3
  45. 12.4
  46. 13.0–13.1
  47. 13.2
  48. 13.3–16.0

History

The ftok() function originates with System V and is typically used by programs that use the System V IPC routines.

Authors

Thorsten Lockert ⟨[email protected]⟩

Bugs

The returned key is computed based on the device minor number and inode of the specified path in combination with the lower 8 bits of the given id. Thus it is quite possible for the routine to return duplicate keys.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.