Linux Message Queue Question

Discussion in 'C Programming' started by Shao Tian, Jul 28, 2010.

  1. Shao Tian

    Shao Tian

    Joined:
    Jul 28, 2010
    Messages:
    2
    In the code below I simply want to send a message to an message queue. and output the number of messages in the queue. But the output is 0.....

    anyone knows whats going on here......

    Thanks very much!!! :D


    #include <stdio.h>
    #include <stdlib.h>
    #include <linux/ipc.h>
    #include <linux/msg.h>
    #include <sys/types.h>
    #include <wait.h>
    #include <unistd.h>
    #include <errno.h>

    typedef struct
    {
    long mtype;
    int veh_type;//1: car, 2: truck
    int pid; //msg id
    } msg;

    main()
    { msg message;
    message.mtype=1;
    message.veh_type=0;
    message.pid=0;

    int qid=msgget(111,IPC_CREAT|0666);
    msgsnd(qid,&message,sizeof(msg),0);

    struct msqid_ds buf;

    msgctl(qid,IPC_STAT,&buf);
    int result=buf.msg_qbytes;
    printf("%d\n",result);
    msgctl(qid,IPC_RMID,0);
    }
     
    Shao Tian, Jul 28, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Russell Warren

    Is Queue.Queue.queue.clear() thread-safe?

    Russell Warren, Jun 22, 2006, in forum: Python
    Replies:
    4
    Views:
    689
    Russell Warren
    Jun 27, 2006
  2. Ikkezelf

    Write message in windows message queue (msmq)

    Ikkezelf, May 2, 2006, in forum: C Programming
    Replies:
    5
    Views:
    716
    Richard Heathfield
    May 2, 2006
  3. Frank Millman
    Replies:
    3
    Views:
    350
    Frank Millman
    Feb 9, 2010
  4. Shao Tian

    Linux Message Queue Question!!!

    Shao Tian, Jul 28, 2010, in forum: C Programming
    Replies:
    0
    Views:
    379
    Shao Tian
    Jul 28, 2010
  5. Kris
    Replies:
    0
    Views:
    491
Loading...

Share This Page