2
누구든지 내 프로그램의 오류가 무엇인지 지적 해 줄 수 있습니까? 사전에메시지 큐 : msgsnd failed : 잘못된 인수
덕분에, 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