LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-09-2018, 04:55 AM   #1
shivendra.ds48
LQ Newbie
 
Registered: Aug 2018
Posts: 8

Rep: Reputation: Disabled
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).
 
Old 08-09-2018, 07:46 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by shivendra.ds48 View Post
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?
 
Old 08-09-2018, 08:07 AM   #3
shivendra.ds48
LQ Newbie
 
Registered: Aug 2018
Posts: 8

Original Poster
Rep: Reputation: Disabled
The code is as below.

#include <stdio.h>
#include <sys/ipc.h>
#include <sys/msg.h>
int main()
{
key_t key;
int msgid;
key=123456789012345;

msgid = msgget(key, 0666 | IPC_EXCL | IPC_CREAT);

printf("key : %#lx\n",key);
printf("message queue %d created\n",msgid);
return 0;
}

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()...??
 
Old 08-09-2018, 08:24 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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));
 
Old 08-09-2018, 08:28 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by shivendra.ds48 View Post
The code is as below.
Code:
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/msg.h>
int main()
{
    key_t key;
    int msgid;
    key=123456789012345;

    msgid = msgget(key, 0666 | IPC_EXCL | IPC_CREAT);

    printf("key : %#lx\n",key);
    printf("message queue %d created\n",msgid);
    return 0;
}
Please use code tags when posting code.
Quote:
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()...??
We again understand what you're asking; we have asked what your goal is, and what context you're doing this in? Have you checked the documentation, and put any debugging statements in your code, to see what's going on?
http://man7.org/linux/man-pages/man2/msgget.2.html
https://www.tldp.org/LDP/lpg/node34.html
 
Old 08-09-2018, 09:01 AM   #6
shivendra.ds48
LQ Newbie
 
Registered: Aug 2018
Posts: 8

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-09-2018, 09:41 AM   #7
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by shivendra.ds48 View Post
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.
 
1 members found this post helpful.
Old 08-14-2018, 04:27 PM   #8
shivendra.ds48
LQ Newbie
 
Registered: Aug 2018
Posts: 8

Original Poster
Rep: Reputation: Disabled
Smile

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.
 
Old 08-15-2018, 07:47 AM   #9
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by shivendra.ds48 View Post
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.
 
1 members found this post helpful.
Old 08-21-2018, 12:37 PM   #10
shivendra.ds48
LQ Newbie
 
Registered: Aug 2018
Posts: 8

Original Poster
Rep: Reputation: Disabled
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Any chance to get length of run queue and swap queue? emJ4y Programming 1 11-03-2010 02:13 PM
packet queue length question vlyamtse Linux - Networking 4 10-08-2009 12:29 AM
io queue length? m1n Linux - Newbie 1 02-25-2009 10:02 AM
Is it possible for me to write in front of queue in case of message queue? hemanthv414 Linux - Newbie 1 11-17-2008 04:40 PM
Network Interface queue length villie Linux - Networking 4 09-03-2004 04:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration