ftok

Understanding Shared Memory Using C

懵懂的女人 提交于 2020-01-04 02:54:32
问题 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, 0); *sharedval = 0; However the second I run that last line, I get a segmentation fault. When debugging, I can print "sharedval" and I get a memory address, presumably the place in memory I got. So I would assume all I have to do is use *sharedval to assess

ftok() collisions

霸气de小男生 提交于 2020-01-02 01:59:13
问题 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 I would like a more robust solution. The application is installed into its own logical volume, and the path supplied to ftok is the binaries directory for the application (within that lv). The IDs supplied start at 1 and there are usually half a

ftok() collisions

天大地大妈咪最大 提交于 2020-01-02 01:59:06
问题 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 I would like a more robust solution. The application is installed into its own logical volume, and the path supplied to ftok is the binaries directory for the application (within that lv). The IDs supplied start at 1 and there are usually half a

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()?

戏子无情 提交于 2019-12-20 18:25:20
问题 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 what I've come to understand, what is needed to access a given shared memory is the shmid , not the key. Or am I wrong? If what we need is the shmid , what is the point in not just creating a random key every time? Edit @Beej's Guide to Unix IPC one

ftok() collisions

萝らか妹 提交于 2019-12-05 02:59:01
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 I would like a more robust solution. The application is installed into its own logical volume, and the path supplied to ftok is the binaries directory for the application (within that lv). The IDs supplied start at 1 and there are usually half a dozen or so. I've tracked down that ftok will do something like this: (id & 0xff) << 24 | (st.st_dev & 0xff

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()?

无人久伴 提交于 2019-12-03 05:41:30
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 what I've come to understand, what is needed to access a given shared memory is the shmid , not the key. Or am I wrong? If what we need is the shmid , what is the point in not just creating a random key every time? Edit @ Beej's Guide to Unix IPC one can read: What about this key nonsense? How do we create one? Well, since the type key_t is actually

Whats is purpose ftok in Message queues

拈花ヽ惹草 提交于 2019-11-27 21:35:07
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 to get our keys rather than using ftok() ? What is the purpose of the argument key in the msget function? #include "sys/msg.h" key = ftok("/home/beej/somefile", 'b'); msqid = msgget(key, 0666 | IPC_CREAT); What is the difference between msqid and key ? The ftok function creates a sort of identifier to be used with the System V IPC functions ( semget

Whats is purpose ftok in Message queues

馋奶兔 提交于 2019-11-26 23:04:43
问题 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 to get our keys rather than using ftok() ? What is the purpose of the argument key in the msget function? #include "sys/msg.h" key = ftok("/home/beej/somefile", 'b'); msqid = msgget(key, 0666 | IPC_CREAT); What is the difference between msqid and