ftok Subroutine
Purpose
Generates a standard interprocess communication key.
Library
Standard C Library (libc.a)
Syntax
Description
The ftok subroutine returns a key, based on the Path and ID parameters, to be used to obtain interprocess communication identifiers. The ftok subroutine returns the same key for linked files if called with the same ID parameter. Different keys are returned for the same file if different ID parameters are used.
All interprocess communication facilities require you to supply a key to the msgget, semget, and shmget subroutines in order to obtain interprocess communication identifiers. The ftok subroutine provides one method for creating keys, but other methods are possible. For example, you can use the project ID as the most significant byte of the key, and use the remaining portion as a sequence number.
Parameters
Item | Description |
---|---|
Path | Specifies the path name of an existing file that is accessible to the process. |
ID | Specifies a character that uniquely identifies a project. |
Return Values
When successful, the ftok subroutine returns a key that can be passed to the msgget, semget, or shmget subroutine.
Error Codes
The ftok subroutine returns the value (key_t)-1 if one or more of the following are true:
- The file named by the Path parameter does not exist.
- The file named by the Path parameter is not accessible to the process.
- The ID parameter has a value of 0.