1

I can't figure out what I missed. The first time that I run this msgget() retuns 0 but msgctl() can remove it. The second time still having 0 and msgctl() aborts with invalid argument error.

Already tried to use some key instead of 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;
}

1 Answer 1

1

== binds more tightly than =. Try putting parentheses around the assignment of queue_id, or put it on its own line:

queue_id = msgget(IPC_PRIVATE, IPC_CREAT | IPC_EXCL | 0600);
if(queue_id == -1) {
         perror("queue");
         return -1;
}

Running your compiler with -Wall -Wextra -Werror will help with this kind of thing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.