Created
April 11, 2011 23:51
-
-
Save vaclavbohac/914630 to your computer and use it in GitHub Desktop.
Delete existing message queue in C.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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