Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

ftok - interprocess communication

&pagelevel(4)&pagelevel

Syntax

#include <sys/ipc.h>

key_t ftok(const char *path, int id);

Description ftok() returns a key which is based on path and id and can be used in subsequent

msgget(), semget() and shmget() system calls. path must be the pathname of an
existing file which can be accessed by the process. id is a character which uniquely
identifies a project.
For all path pointers with which the same file is addressed, ftok() returns the same key if
it is called with the same ID id.
ftok() returns different keys if different IDs id are specified or if various files which are
located in the same file system at the same time are addressed via path. As a rule, ftok()
does not return the same key if it is called up again with the same path and id arguments
but the file thus identified was in the meantime deleted and then created again with the
same name.
Only the 8 least-significant bits of id are used. If these bits are zero, the behavior of ftok()
is undefined.

Return val.

Key of type key_t if successful.

(key_t) -1  if an error occurs. errno is set to indicate the error.

Errors

ftok() will fail if:

EACCES

ELOOP

No search authorization exists for a component of the path prefix.

Too many symbolic links were encountered in resolving path.

ENAMETOOLONG

The pathname pointed to by path is longer than {PATH_MAX}, or the length
of a component of the pathname exceeds {NAME_MAX}; or
the resolving of symbolic links in the pathname leads to an interim result
whose length exceeds {PATH_MAX}.

ENOENT

A component of the pathname does not exist, or path points to an empty
string.

ENOTDIR

A component of the path prefix of path is not a directory.

Notes

To achieve maximum portability, the ID should occupy the least-significant byte in id. The
remaining bytes should be set to 0.

See also

msgget(), semget(), shmget(), sys/ipc.h.