linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Linux Kernel Message Queue Implementation
@ 2003-02-18 14:08 gskiran
  2003-02-18 15:25 ` Erik Mouw
  0 siblings, 1 reply; 2+ messages in thread
From: gskiran @ 2003-02-18 14:08 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 937 bytes --]

[1] msgsnd (int, struct msgbuf *, int, int) INTERFACE ERROR !!

[2] msgsnd() has "struct msgbuf*" as its 2nd parameter. When I tried to write an application which uses message queues for IPC i declared my message queue buffer as -

struct my_msgq_buf
{
    long mtype;
    char *name;
    double amount;
};

I allocated the memory of name dynamically using "malloc" and wrote into the message Queue using msgsnd. And the msgsnd returns successfully. When I do an msgrcv with the above structure type, I always recieve NULL values in my structure buffer !! 

But, When I use the structure as declared below -

struct my_msgq_buf
{
    long mtype;
    char name[30];
    double amount;
};

Every thing interstingly seems to be working fine.! The interface for msgsnd and msgrcv should have "void *" pointers rather than having a "struct msgbuf *" as parameters.

[3] Kernel
[4] 2.4.7-10 
[5] 
[6]
[7] i586. Intel Pentium 166 MHz MMX.
[8]


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Linux Kernel Message Queue Implementation
  2003-02-18 14:08 Linux Kernel Message Queue Implementation gskiran
@ 2003-02-18 15:25 ` Erik Mouw
  0 siblings, 0 replies; 2+ messages in thread
From: Erik Mouw @ 2003-02-18 15:25 UTC (permalink / raw)
  To: gskiran; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1685 bytes --]

On Tue, Feb 18, 2003 at 02:22:13PM +0000, gskiran@bgl.vsnl.net.in wrote:
> [1] msgsnd (int, struct msgbuf *, int, int) INTERFACE ERROR !!

No, user error.

> [2] msgsnd() has "struct msgbuf*" as its 2nd parameter. When I tried
> to write an application which uses message queues for IPC i declared
> my message queue buffer as -
> 
> struct my_msgq_buf
> {
>     long mtype;
>     char *name;
>     double amount;
> };

Nothing wrong over here, except that your pointer is ONLY valid in the
sending process, and NOT in the receiving process.

> I allocated the memory of name dynamically using "malloc" and wrote
> into the message Queue using msgsnd. And the msgsnd returns
> successfully. When I do an msgrcv with the above structure type, I
> always recieve NULL values in my structure buffer !!
> 
> But, When I use the structure as declared below -
> 
> struct my_msgq_buf
> {
>     long mtype;
>     char name[30];
>     double amount;
> };
> 
> Every thing interstingly seems to be working fine.!

Yes, which was to be expected cause "name" is now in the the message
structure.

>  The interface for
> msgsnd and msgrcv should have "void *" pointers rather than having a
> "struct msgbuf *" as parameters.

No, it's right the way it is right now. You are making the mistake that
you think pointers are valid memory references among all processes,
which clearly is not the case.

Get the book "Advanced programming in the Unix environment" by W.
Richard Stevens. It's more than worth its price and explains SysV IPC
in a very thorough way.


Erik

-- 
J.A.K. (Erik) Mouw
Email: J.A.K.Mouw@its.tudelft.nl  mouw@nl.linux.org

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-02-18 15:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-18 14:08 Linux Kernel Message Queue Implementation gskiran
2003-02-18 15:25 ` Erik Mouw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).