C 创建队列消息在id中返回零
我不知道我错过了什么。我第一次运行这个C 创建队列消息在id中返回零,c,C,我不知道我错过了什么。我第一次运行这个msgget()retuns 0,但是msgctl()可以删除它。第二次仍具有0和msgctl()的操作将中止,并出现无效参数错误 已尝试使用某些密钥而不是IPC\u PRIVATE #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include &l
msgget()retuns 0
,但是msgctl()
可以删除它。第二次仍具有0
和msgctl()
的操作将中止,并出现无效参数错误
已尝试使用某些密钥而不是IPC\u PRIVATE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <sys/msg.h>
#include <time.h>
#define DEBUG
int main(){
int queue_id;
if(queue_id = msgget(IPC_PRIVATE, IPC_CREAT | IPC_EXCL | 0600) == -1){
perror("queue");
return -1;
}
if(msgctl(queue_id, IPC_RMID, NULL) == -1) {
perror("queue rmid:");
}
return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#定义调试
int main(){
int队列标识;
如果(队列id=msgget(IPC_专用,IPC_创建| IPC_排除| 0600)=-1){
佩罗(“队列”);
返回-1;
}
如果(msgctl(队列id、IPC\U RMID、NULL)=-1){
perror(“队列rmid:”);
}
返回0;
}
=
比=
绑定得更紧。尝试在队列\u id
的分配周围加上括号,或将其放在自己的行上:
queue_id = msgget(IPC_PRIVATE, IPC_CREAT | IPC_EXCL | 0600);
if(queue_id == -1) {
perror("queue");
return -1;
}
使用-Wall-Wextra-Werror
运行编译器将有助于解决这类问题