[英]Creating a Message Queue using msgget in Linux in a .c file Receiving function not implementing error
當msgget運行時,我收到一個錯誤,我的代碼在返回msgget行時給我一個返回:“:Function not Implemented”。 我已經嘗試了很多選項,我在Windows 10上運行UBUNTU請大家幫忙,這里是我的代碼和終端窗口結果:CODE:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/ipc.h>
#include <fcntl.h>
#include <sys/msg.h>
#include <sys/types.h>
#include "msg.h"
void main(int argc, char *argv[]){
int msgQid;
int flg = IPC_CREAT | 0644;
key_t k;
message_buf sndbuf;
message_buf rdbuf;
size_t buf_lng;
k= atoi(argv[2]);
if(argc == 3){
if(k>1){
if(strcmp(argv[1],"-c")==0 || strcmp(argv[1],"-C")==0){
//Create Message Queue
if((msgQid=msgget(k, flg))<0){
perror("msgget: EXITING...\n");
exit(EXIT_FAILURE);
}
else{
printf("Queue Created: %d\n",msgQid);
}
exit(0);
}
else if(strcmp(argv[1],"-d")==0 || strcmp(argv[1],"-D")==0){
//Delete Message Queue
flg=0666;
if((msgQid=msgget(k, flg))==-1){
printf("Message Queue Does Not Exist\n");
exit(EXIT_FAILURE);
}
else{
printf("Queue Found: %d\n",msgQid);
if((msgctl(msgQid, IPC_RMID, NULL))==-1){
fprintf(stderr,"Failed to Delete Queue\n");
exit(EXIT_FAILURE);
}
else{
printf("Queue Deleted: %d\n", msgQid);
}
}
exit(0);
}
}
else{
//if not -c/-C or -d/-D then error
fprintf(stderr, "Incorrect Usage of Flag\n");
exit(EXIT_FAILURE);
}
}
else{
fprintf(stderr, "Invalid Key: %s\n", argv[2]);
exit(EXIT_FAILURE);
}
if(argc == 4){
if(argv[1]=="-r" || argv[1]=="R"){
//Receive message of type from queue
if((msgQid=msgget(k, flg))<0){
perror("msgget: In MSG RECEIVE");
exit(1);
}
if((msgrcv(msgQid, &rdbuf, MSGSZ, k, 0)) <0){
perror("message receive");
exit(1);
}
printf("%s\n", rdbuf.mtext);
exit(EXIT_SUCCESS);
}
}
if(argc == 5){
if(argv[1]=="-s" || argv[1]=="S"){
//Send message of type to queue
if((msgQid=msgget(k, flg))<0){
perror("msgget: In MSG RECEIVE");
exit(1);
}
sndbuf.mtype = atoi(argv[3]);
strncpy(sndbuf.mtext, argv[4], MSGSZ);
buf_lng = strlen(sndbuf.mtext)+1;
if((msgsnd(msgQid, &sndbuf, buf_lng, IPC_NOWAIT))<0){
fprintf(stderr, "%d, %ld, %s, %d\n", msgQid, sndbuf.mtype, sndbuf.mtext, (int)buf_lng);
perror("Message Send");
exit(EXIT_FAILURE);
}
exit(0);
}
}
else{
printf("DOES NOT FIT CRITERIA\n");
}
}
終端窗口:
victoria @ DESKTOP-865C589:/ mnt / c / Users / toria / Documents $ gcc -o MSGQ msgQtest.c victoria @ DESKTOP-865C589:/ mnt / c / Users / toria / Documents $ ./MSGQ -c 100
msgget:退出...
:功能未實現victoria @ DESKTOP-865C589:/ mnt / c / Users / toria / Documents $
不幸的是,Windows子系統Linux上沒有消息隊列:(
Windows上不支持消息隊列,即使使用Cygwin也是如此。 但是看看這個GitHub線程 ,似乎這些調用將在不久的將來實現。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.