[問題] Message queue in embedded linux

看板Programming作者 (聽某嘴大富貴)時間16年前 (2008/02/26 13:56), 編輯推噓0(005)
留言5則, 2人參與, 最新討論串1/1
※ [本文轉錄自 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,
你改用fprintf(stderr,"")試試看,如果console是用
02/26 03:15

02/26 03:16,
serial port輸出,也許會有buffered I/O的問題
02/26 03:16

02/26 13:53,
還是一樣耶@@
02/26 13:53

02/26 13:54,
在PC上 假如我只run P1, P3一樣show出message
02/26 13:54

02/26 13:54,
但是在板子上, 只跑P1, 則P3完全沒有顯示任何資訊Orz
02/26 13:54
-- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.122.184.20

02/26 23:12, , 1F
If (msgflg & IPC_NOWAIT) is 0.suspend
02/26 23:12, 1F

02/27 08:46, , 2F
不好意思, 可以請大大解釋詳細一點嗎?!
02/27 08:46, 2F

02/27 10:07, , 3F
請自行查閱man, 上面已寫得很清楚了
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
文章代碼(AID): #17mwe89I (Programming)