COHERENT manpages
This page displays the COHERENT manpage for ftok() [Generate keys for interprocess communication].
List of available manpages
Index
ftok() -- General Function (libc) Generate keys for interprocess communication #include <sys/types.h> #include <sys/ipc.h> key_t ftok(filename, procid) char *filename; char procid; The COHERENT system implements three methods by which one process can communicate with another: semaphores, messages, and shared memory. In each case, a process must use a key of type key_t (which is defined in header file <sys/types.h>) to identify itself. One problem is that each process generates its own key, by its own method. Therefore, two processes could independently generate the same key, which could create serious problems for interprocess communication. The function ftok() generates keys for processes that perform interprocess communication. filename is the full path name of a file. This can be the full path name of the file in which the program resides on disk. The file named in filename must exist and be accessible for the system call stat(), or ftok() will fail. procid is a one-character identifier with which this process distinguishes itself from all other processes that are pegged to filename. How a process generates procid is up to the program itself. For example, the program myproc can generate a unique key for itself with the call: key_t mykey; mykey = ftok("/usr/bin/myproc", 'A'); Note the following caveats: -> Because ftok() generates its key from a file's i-node major and minor numbers rather than its name, it generates the same key for two files that are linked. For example, if files /usr/henry/foo and /usr/henry/bar are linked to each other, then the calls ftok("/usr/henry/foo", 'A'); and ftok("/usr/henry/bar", 'A'); will generate the same key. -> If the file named by filename is destroyed and then recreated, the call to ftok() generates a different key than it did before filename was destroyed. -> If the file named by filename does not exist, ftok() returns (key_t) -1. Example For an example of this function, see the entry for msgget(). See Also ipc.h, libc, msgget(), semget(), shmget()