3

POSIXキューで開始点でスタックしています:

(私が思うに)ブロックすべきものはまったくブロックされておらず、ループは回転し続けます。いくつかのメッセージが到着するまでプロセスをブロックしようとしていmq_receiveますが、呼び出しは常にキューから空のメッセージを受信して​​いるようです(ただし、メッセージを送信しているクライアントはまだありません)。キューは、デフォルト設定の。で正しく開かれますmq_flags=0

Ubuntu12.04を実行しています。

コードは次のとおりです。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <fcntl.h>
#include <sys/stat.h>
#include <mqueue.h>

int main(int argc, char **argv) {
    mqd_t qd;
    qd = mq_open("/tempqueue", O_RDONLY | O_CREAT, 0666, NULL);
    if (qd == (mqd_t) -1){
        printf("Problemz");
        return 1;
    }else{
        printf("Coda creata\n");
    }

    char buf[400];

    while(1){
        mq_receive(qd, buf, 400, NULL);
        printf("Ricevo: %s.\n", buf);
    }

    mq_close(qd);
    mq_unlink("/tempqueue");
}
4

1 に答える 1

7

戻り値を確認してください!

It's almost certainly "-1" ... and which point you can call "perror()" or check "errno" for the underlying error:

于 2013-02-06T23:52:11.520 に答える