[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1

ftok Subroutine

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 ( PathID)
char *Path;
int ID;

Description

Attention: If the Path parameter of the ftok subroutine names a file that has been removed while keys still refer to it, the ftok subroutine returns an error. If that file is then re-created, the ftok subroutine will probably return a key different from the original one.
Attention: Each installation should define standards for forming keys. If standards are not adhered to, unrelated processes may interfere with each other's operation.
Attention: The ftok subroutine does not guarantee unique key generation. However, the occurrence of key duplication is very rare and mostly for across file systems.

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

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:

Related Information

The msgget (msgget Subroutine) subroutine, semget subroutine, shmget subroutine.

Subroutines Overview and Understanding Memory Mapping in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]