Skip to content

Instantly share code, notes, and snippets.

@vaclavbohac
Created April 11, 2011 23:51
Show Gist options
  • Save vaclavbohac/914630 to your computer and use it in GitHub Desktop.
Save vaclavbohac/914630 to your computer and use it in GitHub Desktop.
Delete existing message queue in C.
// Deletes message queue in C.
// For educational purposes only.
// Author: Vaclav Bohac
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
int main ( void )
{
int key, mask, msgid;
key = getuid();
mask = 0666;
msgid = msgget(key, mask);
if (msgid == -1) {
printf("Message queue does not exist.\n");
exit(EXIT_SUCCESS);
}
if (msgctl(msgid, IPC_RMID, NULL) == -1) {
fprintf(stderr, "Message queue could not be deleted.\n");
exit(EXIT_FAILURE);
}
printf("Message queue was deleted.\n");
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment