length of key_t in msgget function for message queue
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
length of key_t in msgget function for message queue
msgget() function needs key_t and IPC_CREATE as an argument. If i put the key upto 10 digit, every things is normal and i get the queue with the correct value of hexadecimal key(8 characteres). But if I increase the value of key and hexadecimal value increases from 8 characters, then it takes only last 8 characters and truncates the rest from starting.
Is there any limits for the number of characters of key_t in linux.
I am using Red Hat Enterprise Linux Server release 6.3 (Santiago).
msgget() function needs key_t and IPC_CREATE as an argument. If i put the key upto 10 digit, every things is normal and i get the queue with the correct value of hexadecimal key(8 characteres). But if I increase the value of key and hexadecimal value increases from 8 characters, then it takes only last 8 characters and truncates the rest from starting. Is there any limits for the number of characters of key_t in linux.
I am using Red Hat Enterprise Linux Server release 6.3 (Santiago).
Since you don't post your code, tell us what you're trying to do, or even why you're trying to do it (context? Goals?), what do you think we'll be able to tell you? Read the "Question Guidelines" link in my posting signature, and provide details, and we can try to assist.
Past that, have you contacted RHEL support, since you're PAYING FOR RHEL, RIGHT?
When posting code, please use [code] tags to enclose it, the result appears like this:
Code:
#include <example.h>
// This is code
void main(void)
{
// spacing is preserved
}
As far as understanding the nature of a key_t type define, you can look at the includes in your system to tell you what a key_t is defined to be, likely it is an integer and likely that is 32-bits.
Another thing you can do is just test by writing some code:
Code:
printf("Size of a key_t is: %d\n", sizeof(key_t));
The Queue is created with the key value as : 0x860ddf79
However the value for key(123456789012345) as per code should be : 7048860DDF79
i.e. it is truncating the first four characters and making the Queue with the value of 860DDF79. Is there any limit for the length of the key_t used in msgget()...??
The print statement gives the following output : Size of a key_t is: 4.
Goal is to create 2 unique message queue. For this i need to pass two unique keys.
For the first time i pass the key as : 2249056121 . Whose hexadecimal value is given as : 860DDF79
For the second time i pass the key as : 123456789012345. whose hex value is given as : 7048860DDF79
But creating the queue takes only 8 characters and same queue is being created even after giving the two different value of key.
The purpose is not completed as i am not able to create two queue for two different key value.
I have checked the documentation and there is no such information regarding key size.
Last edited by shivendra.ds48; 08-09-2018 at 09:04 AM.
The print statement gives the following output : Size of a key_t is: 4.
Goal is to create 2 unique message queue. For this i need to pass two unique keys.
For the first time i pass the key as : 2249056121 . Whose hexadecimal value is given as : 860DDF79
For the second time i pass the key as : 123456789012345. whose hex value is given as : 7048860DDF79
But creating the queue takes only 8 characters and same queue is being created even after giving the two different value of key.
The purpose is not completed as i am not able to create two queue for two different key value.
I have checked the documentation and there is no such information regarding key size.
You answered your own question when you printed out the size of a key_t. Technically it is documented by way of the variable type being a key_t where you can check the include file to determine how that type define is made.
Stop thinking of it as a string. The variable is limited to 32-bits only. This gives you 4.3 billion possible values.
You do not have to force a value, if you give it the CREATE flag it will return you a value and you just use that.
Not trying to be mean, but I'm somewhat concerned that you seem to be using a core OS programming API but you do not even understand a fundamental part of the language. If this is experimentation, I suggest starting more fundamental. If this is something else, such as work, I suggest you inform others that this topic is at or above the limit of your programming knowledge. If this is school work, I suggest you check with your instructor.
Since you're using RHEL, then you're likely using a production server, or you have a demo copy of RHEL. If on a production server, then be careful what programs you write and test, they may not be helpful to the body of other users at large. If a demo copy, fine, however there are plenty of other Linux distributions that are probably more suitable for general programming experimentation.
Dear rtmistler,
Thanks for your support. This is not a college project neither a small application. Can't tell you the exact thing as its confidential. Its just the simplest form in which i can explain you the issue. Actually its a huge application i am working in. Probably where its quiet difficult to change the existing logic. I have gone through all the documentation and cant find any restriction on the number of message queue generated and id formed by it. If i would have to change the logic, I would have done it without asking here.
Probably if you understand that the support means a lot to us here. And we come here when we tried a lot and exhausted most of our mind for the issue.
Dear rtmistler,
Thanks for your support. This is not a college project neither a small application. Can't tell you the exact thing as its confidential. Its just the simplest form in which i can explain you the issue. Actually its a huge application i am working in. Probably where its quiet difficult to change the existing logic. I have gone through all the documentation and cant find any restriction on the number of message queue generated and id formed by it. If i would have to change the logic, I would have done it without asking here.
Probably if you understand that the support means a lot to us here. And we come here when we tried a lot and exhausted most of our mind for the issue.
I feel you need to greatly expand your diagnosing and debugging capabilities when you program. If it is a huge application, then it is maintained by a very large team, and there should be some resident experts available to consult about these fundamental things.
Not saying that it is improper to ask questions on LQ. Would suggest that you review the link in my signature about how to use Linux Questions so that you understand how to best pose your questions and ask them more clearly.
There's nothing new about working on something proprietary or private, those are everyday things. Meanwhile, I feel you have an excellent opportunity to seek out more senior members of your team in a one-on-one manner and be able to obtain very helpful tips on debugging.
For instance, my tip about how to print out the size of that variable and what you could learn from it. There are dozens, or more, tips which you likely could pick up from a more senior programmer. Therefore I would suggest that you seek out one or more of them to help you learn more about the architecture which you are programming within.
Finally after a lot of research, I have to change the logic of the application to work and to get rid of the issue. Thank you all for the solution and discussion.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.