Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 创建队列消息在id中返回零_C - Fatal编程技术网

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
运行编译器将有助于解决这类问题