[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Base Operating System and Extensions Technical Reference, Volume 1

ftok Subroutine


Generates a standard interprocess communication key.


Standard C Library (libc.a)


#include <sys/types.h>
#include <sys/ipc.h>
key_t ftok (PathID)
char *Path;
int ID;


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.

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.


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:

Implementation Specifics

This subroutine is part of Base Operating System (BOS) Runtime.

Related Information

The msgget subroutine, semget subroutine, shmget subroutine.

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

[ Previous | Next | Contents | Glossary | Home | Search ]