我无法弄清楚我错过了什么。我第一次运行这个msgget() retuns 0
,但msgctl()
可以删除它。第二次仍然有0
和msgctl()
中止无效参数错误。
已经尝试使用一些键而不是IPC_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;
}
==
比=
更紧密地束缚。尝试在queue_id
的赋值周围加上括号,或者将它放在自己的行上:
queue_id = msgget(IPC_PRIVATE, IPC_CREAT | IPC_EXCL | 0600);
if(queue_id == -1) {
perror("queue");
return -1;
}
使用-Wall -Wextra -Werror
运行编译器将有助于此类事情。