[問題] Message queue in embedded linux
※ [本文轉錄自 Linux 看板]
作者: ckf (聽某嘴大富貴) 看板: Linux
標題: [問題] Message queue in embedded linux
時間: Mon Feb 25 22:02:51 2008
我在三個processes間利用message queue來傳遞資料
P1 --> |========| --> P3 <-- |========|<-- P2
P3是最主要的程序
他分別到P1與P2的queue取得需要的資料作計算
由於P1和P2寫入的時間不同
所以在P3的msgrcv的type設定為IPC_NOWAIT
在一般PC上運作沒有問題
有資料就讀 沒資料就略過(return -1)
但是相同的程式我把他放進embedded linux(kernel 2.4)上面跑卻發生block的狀況
即使P1寫入資料到queue_P1 若P2沒有寫資料到queue_P2 P3就無法讀值
(P1寫入的時間變化較大 大約xxms寫入一次 而P2設定每秒寫入一次)
請問有可能是什麼問題呢??
希望是因為程式寫不好 而不是因為系統的關係 @@
請各位大大指導 謝謝
--
下面是接收(P3)的程式片段:
#define MSGQ_PATH "/tmp"
#define MSGQ_ID1 111
#define MSGQ_ID2 222
typedef struct {
long mtype;
float msg;
}msgq_t;
int main(int argc, char *argv[]) {
key_t key1, key2;
int msgqid1, msgqid2;
msgq_t msg1, msg2;
if ( (key1 = ftok(MSGQ_PATH, MSGQ_ID1)) == -1 ) {
perror("ftok1");
return -1;
}
if ( (key2 = ftok(MSGQ_PATH, MSGQ_ID2)) == -1 ) {
perror("ftok2");
return -1;
}
if ( (msgqid1 = msgget(key1, 0666 | IPC_CREAT)) == -1 ) {
perror("msgget1:");
return -1;
}
if ( (msgqid2 = msgget(key2, 0666 | IPC_CREAT)) == -1 ) {
perror("msgget2:");
return -1;
}
while(1) {
if ( (msgrcv(msgqid1, &msg1, sizeof(msg1), 0, IPC_NOWAIT)) ==
-1 ) {
//perror("msgrcv1:");
//return -1;
}
else
printf("queue1 : %f\n", msg1.msg);
if ( (msgrcv(msgqid2, &msg2, sizeof(msg2), 0, IPC_NOWAIT)) ==
-1 ) {
//perror("msgrcv2:");
//return -1;
}
else
printf("queue2 : %f\n", msg2.msg);
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.84.63.244
推
02/26 03:15,
02/26 03:15
→
02/26 03:16,
02/26 03:16
→
02/26 13:53,
02/26 13:53
→
02/26 13:54,
02/26 13:54
→
02/26 13:54,
02/26 13:54
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.122.184.20
→
02/26 23:12, , 1F
02/26 23:12, 1F
→
02/27 08:46, , 2F
02/27 08:46, 2F
→
02/27 10:07, , 3F
02/27 10:07, 3F
→
02/27 10:08, , 4F
02/27 10:08, 4F
→
02/27 10:08, , 5F
02/27 10:08, 5F