2
任何人都可以請幫我指出我的程序中有什麼錯誤?消息隊列:msgsnd失敗:無效參數
由於提前, kingsmasher1
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <string.h>
#include <errno.h>
typedef struct msgbuf {
long mtype; /* message type, must be > 0 */
char mtext[15]; /* message data */
} msgbuf;
int main() {
key_t key;
int msqid, pid, length;
msgbuf buf;
msqid=msgget(IPC_PRIVATE,IPC_CREAT);
if(msqid==-1){
perror("msgget failed");
return;
}
else {
printf("msgget succeeded. ID:%u",msqid);
}
pid=fork();
if(pid==-1) {
perror("fork failed\n");
}
buf.mtype=1;
strcpy(buf.mtext, "This is a test message");
length=sizeof(buf.mtext);
if(msgsnd(msqid,&buf,length,0)!=0) {
perror("msgsnd failed:\n");
}
else {
printf("msgsnd succeeded\n");
}
}
輸出: 的msgsnd失敗:無效的參數
謝謝,它解決了:-) – kingsmasher1 2011-03-07 16:17:10