C programming language: key_t ftok(const char *pathname, int proj_id); The ftok() function uses the identity of the file named by the given pathname (which must refer to an existing, accessible file) and the least significant 8 bits of proj_id (which must be nonzero) to generate a key_t type System V IPC key, suitable for use with msgget(2), semget(2), or shmget(2).
Questions tagged [ftok]
17 questions
16
votes
3 answers
Whats is purpose ftok in Message queues
I have started reading message queues one of the IPC mechanism on Linux .But at very first step I have some very basic questions.
Use of ftok() to generate unique ID (key) and what is unique ID which is to be generated.
Can't we use simple a number…

Amit Singh Tomar
- 8,380
- 27
- 120
- 199
16
votes
4 answers
Which file should I pass as pathname argument of ftok()
It is mentioned in ftok() manual
key_t ftok(const char *pathname, int proj_id);
The ftok() function uses the identity of the file named by the given pathname (which must refer to an existing, accessible file) ...
I am confused about const char…

Andrew-Dufresne
- 5,464
- 7
- 46
- 68
15
votes
3 answers
What is the point of having a key_t if what will be the key to access shared memory is the return value of shmget()?
When using shared memory, why should we care about creating a key
key_t ftok(const char *path, int id);
in the following bit of code?
key_t key;
int shmid;
key = ftok("/home/beej/somefile3", 'R');
shmid = shmget(key, 1024, 0644 | IPC_CREAT);
From…

devoured elysium
- 101,373
- 131
- 340
- 557
9
votes
2 answers
ftok() collisions
I am using ftok() to generate identifiers for shared memory segments used by a C application. I am having problems, where on one box I am getting collisions with the identifiers used by root. I can fix it in this instance by hacking the code, but…

asc99c
- 3,815
- 3
- 31
- 54
4
votes
4 answers
Understanding Shared Memory Using C
Using C, I'm trying to set up shared memory. My code looks like:
key_t key = ftok("SomeString", 1);
static int *sharedval;
int shmid = shmget(key, sizeof(int), S_IRUSR | S_IWUSR); // less permissions
sharedval = (int *) shmat(shmid, NULL,…

adammenges
- 7,848
- 5
- 26
- 33
3
votes
1 answer
What is this "project identifier" in ftok()?
The second parameter proj_id. What is it?
#include
#include
key_t ftok (const char *pathname, int proj_id);

Pradyumna Reddy
- 31
- 4
2
votes
1 answer
how to determine ftok shared memory collision
I'm trying to debug a problem with some legacy code. While trying to understand what I'm looking at, I found that it builds two unique shared memory space using ftok. I looked online to see what it does and I stumbled upon this link. I looked…

adi
- 23
- 2
2
votes
4 answers
Creating unique keys for a message quene for an app that can have multiple instances
I have made a Linux CUI app that communicates between processes via Message-quene.
There is no problem with it as long as it is a single instance. However when there are multiple instances of the same app, the messages in the quene get sent to the…

Saifis
- 2,197
- 1
- 22
- 36
2
votes
2 answers
What is the formula used to produce a ftok() key?
What is the formula used to produce a key that ftok() produces? ftok is a Linux function for creating keys for SYSTEM V IPC.

test
- 21
- 1
- 4
1
vote
2 answers
How to fix the error Permission denied while using msgrcv in C
I want to make a programm in C that receive a message from messaging queue.
I have the existing code here :
typedef struct {
long id;
char mes[20];
} message;
int main() {
key_t cle = ftok(".",0);
if(cle == -1){
…

TheHangel
- 21
- 1
1
vote
2 answers
error: Invalid argument; while sending msgsnd() message; not matching queue ID
I was just learning IPC on linux and come up with three simple programs. One is made to create (and administrate in the feature) the message queue. The second should just send the message to the queue created by the first one. The third program is…

siery
- 467
- 3
- 20
1
vote
2 answers
Error with msgget() and ftok ()
I am learning IPC programming. As a part of it I tried the below two codes to get to know about message queues....
Message queue creator or message sender
struct my_msgbuf {
long mtype;
char mtext[200];
};
int main(void)
{
struct…

raka
- 133
- 1
- 4
- 11
0
votes
0 answers
QT on Cygwin -- IPC Errors
I've downloaded the source for QT 5.6.0 and I'm attempting to compile/install it on a Cygwin installation for Windows.
The Cygwin build already has Qt4 and Qt3 libraries installed. Trying to upgrade so I can install the latest QtCreator suite.
Here…

Jason R. Mick
- 5,177
- 4
- 40
- 69
0
votes
0 answers
How to delete the key created by the ftok() function
int main(void) {
key_t key = ftok("/sys/ipc", 0);
int shmid = shmget(key, 1024, IPC_CREATE | 0x0604);
}
when I run this code second time, because the key collision so the value of shmid is -1
How can I delete the key I set before?

刘健坤
- 1
0
votes
0 answers
Call ftok from java using JNA (on remote session)
When I try to call ftok from java using JNA every time I get different key for the same file path and id parameters. Is there some reason in ftok implementation or/and in JVM working mechanism that cause this situation? In native code it's fine -…

Flxb
- 33
- 4