[英]How POSIX Message Queue names used in makefile
我有與操作系統課程相關的作業。 在本作業中,將實現兩個程序:名為“ get”的客戶端程序和名為“ iserv”的服務器程序。 該服務器將是一個多進程程序。 POSIX消息隊列將用於進程間通信。 服務器將按以下方式啟動:iserv在此是服務器要創建的消息隊列的名稱。 是包含整數的文本文件的名稱。
我的iserv.c程序:(未完成)
#include <linux/types.h>
#include <linux/unistd.h>
#include <stdio.h>
#include <mqueue.h>
#include <stdlib.h>
#include <linux/string.h>
#include <linux/fcntl.h>
#include <linux/errno.h>
#include <linux/wait.h>
#include <msg.h>
int main(int argc , char *argv[])
{
pid_t apid1;
FILE *fp;
mqd_t mq;
const char *msgqueue = "/serverqueue";
int oflag = (O_RDWR|O_CREAT);
mode_t mode = (S_IRUSR|S_IWUSR);
struct mq_attr *attr = NULL;
if(argc != 1)
{
printf("wrong number of arguments");
exit(1);
}
//create message queue
mq = mq_open(msgqueue ,oflag , mode , attr);
if(mq==-1)
{
perror("can not open msg queue\n");
exit(1);
}
printf("mq opened , mq id = %d\n" , (int) mq);
//create child process
apid1 = fork();
if(apid1 < 0)
{
perror("main():");
exit(1);
}
if(apid1 == 0)
{
printf("this is the first child, pid = %d\n", (int) getpid());
fflush(stdout);
}
}
如代碼所示,將使用名稱“ serverqueue”創建消息隊列。 然后,我將我的makefile創建為:
iserv:iserv.c
gcc -o iserv serverqueue infile.txt -lrt
clean:
rm -r *.o iserv
當我使用make命令運行此makefile時,出現服務器隊列:沒有此類文件或目錄錯誤。 iserv行將在何處以及如何啟動服務器? 哪里錯了?
請幫助我,謝謝!
你的makefile文件對我來說毫無意義。 -o指定編譯的輸出文件的名稱。 如果您的源文件名為iserv.c,並且您希望將可執行文件命名為serverqueue,請進行編譯
gcc -o serverqueue iserv.c -lrt
在您的makefile中,您忘記了源文件的.c擴展名。
我不明白您之所以包含infile.txt的原因。
根據您的評論進行編輯:
在家庭作業中,希望按以下方式啟動服務器:iserv。 servq是要由服務器創建的消息隊列的名稱,如果我為真,則在代碼中將其作為服務器隊列創建,此外inputfile是將包含大量正整數的文本文件的名稱。
不,語句iserv <servq> <inputfile>
與編譯無關。 一旦程序被編譯,這就是應該使用該程序的方式。 該程序的名稱是iserv,因此您必須像這樣編譯代碼
gcc -o iserv iserv.c -lrt
開始您的程序類型
./iserv <servq> <inputfile>
其中<servq>
是您的服務器隊列,而<inputfile>
將是infile.txt。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.