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.
I found this topic has been discussed previously by many. But my issue is quite unique. I am trying with a simple sender receiver program using message queue. Below is the sample code -
I found that the code get hang exactly at msgsnd() function. If I am using IPC_NOWAIT flag it will throw error. If I am restarting my system this program work fine for 1st time. And then for 2nd time and onwards the same issue persist.
Please use [code] tags to enclose your code. I have a link in my signature which may help describe.
If you're saying that this works sometimes and not others, then within your fprintf() statement of the failure, also output the errno value which msgsnd() has returned.
There are a LOT of possibilities here, see the man page for msgsnd(2):
Code:
RETURN VALUE
On failure both functions return -1 with errno indicating the error, otherwise msgsnd() returns 0 and
msgrcv() returns the number of bytes actually copied into the mtext array.
ERRORS
When msgsnd() fails, errno will be set to one among the following values:
EACCES The calling process does not have write permission on the message queue, and does not have the
CAP_IPC_OWNER capability.
EAGAIN The message can't be sent due to the msg_qbytes limit for the queue and IPC_NOWAIT was specified
in msgflg.
EFAULT The address pointed to by msgp isn't accessible.
EIDRM The message queue was removed.
EINTR Sleeping on a full message queue condition, the process caught a signal.
EINVAL Invalid msqid value, or nonpositive mtype value, or invalid msgsz value (less than 0 or greater
than the system value MSGMAX).
ENOMEM The system does not have enough memory to make a copy of the message pointed to by msgp.
When msgrcv() fails, errno will be set to one among the following values:
E2BIG The message text length is greater than msgsz and MSG_NOERROR isn't specified in msgflg.
EACCES The calling process does not have read permission on the message queue, and does not have the
CAP_IPC_OWNER capability.
EAGAIN No message was available in the queue and IPC_NOWAIT was specified in msgflg.
EFAULT The address pointed to by msgp isn't accessible.
EIDRM While the process was sleeping to receive a message, the message queue was removed.
EINTR While the process was sleeping to receive a message, the process caught a signal; see signal(7).
EINVAL msgqid was invalid, or msgsz was less than 0.
ENOMSG IPC_NOWAIT was specified in msgflg and no message of the requested type existed on the message
queue.
Thanks for your reply. I had checked the errno when it hangs. The errno belongs to 11 which is EAGAIN i.e. buffer is full. Why the same is not happening for the 1st time when I run the program ??
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.