ftok
Purpose
Generates a standard interprocess communication key.
Library
Standard C Library (libc.a)
Syntax
#include <sys/types.h>
#include <sys/ipc.h>
key_t ftok (path, id)
char *path;
char id;
Description
The ftok subroutine returns a key, based on the path and
id parameters, to be used to obtain interprocess communi-
cation identifiers. The path parameter must be the path
name of an existing file that is accessible to the
process. The id parameter must be a character that
uniquely identifies a project. ftok returns the same key
for linked files if called with the same id parameter.
Different keys are returned for the same file if dif-
ferent id parameters are used.
All interprocess communication facilities require you to
supply a key to the msgget, semget, and shmget system
calls in order to obtain interprocess communication iden-
tifiers. The ftok subroutine provides one method of cre-
ating keys, but many others are possible. Another way to
do this, for example, is to use the project ID as the
most significant byte of the key, and to use the
remaining portion as a sequence number.
Warning: It is important for each installation to define
standards for forming keys. If some standard is not
adhered to, then it is possible for unrelated processes
to interfere with each other's operation.
Warning: If the path parameter of the ftok subroutine
names a file that has been removed while keys still refer
it, then the ftok subroutine returns an error. If that
file is then recreated, the ftok subroutine will probably
return a different key than the original one.
Return Value
Upon successful completion, the ftok subroutine returns
a key that can be passed to the msgget, semget, or shmget
system call. The ftok subroutine returns (key_t) -1 if
one or more of the following are true:
o The file named by the path parameter does not exist.
o The file named by the path parameter is not acces-
sible to the process.
o The id parameter is 0 ("'\0'").
Related Information
In this book: "msgget," "semget," and "shmget."