FIFO-сервер не отвечает клиенту ??? - PullRequest
0 голосов
/ 05 октября 2018

Сервер начинает с запроса количества клиентов и начального объема памяти в терминах фреймов.

Клиент обращается к серверу только один раз!Клиент отправляет серверу запрос памяти и имя задания через общий FIFO (то, что мы назвали FIFO_to_server), который направляется непосредственно на сервер.Используйте как минимум 3 клиента.

После того, как всем подходящим клиентам будет выделена память, покажите «карту» выделенной памяти на стороне сервера.

В системе ожидается не менее трех клиентов.Каждый клиент: 1. Запрашивает имена заданий и запрос памяти от пользователя.2. Отправляет имя и объем памяти для каждого клиента на сервер через общий FIFO, который используется всеми клиентами.3. Клиент прекращает работу.4. Примечание: программа client pro будет одной программой, которая запускается 3 раза, поэтому вы откроете несколько окон, в которых запущена программа клиента.Минимальное количество клиентов должно быть 3, а максимальное может быть вашим выбором.Вы будете использовать один общий FIFO, который создается и открывается сервером только один раз.Сервер: 1. Запрашивает и получает целое число, которое определяет количество клиентов (с клавиатуры на сервере, и это будет не менее 3) и общий объем памяти с точки зрения количества 256-байтовых кадров.2. Получает имена заданий и запросы памяти от каждого клиента через общий FIFO.3. Действует как менеджер памяти, назначая страницы для фреймов для клиентов.4. Рассчитывает внутреннюю фрагментацию в конечном кадре каждого клиента.5. После завершения всех клиентов сервер отключается.

Мой сервер не может отправить результат клиенту, даже если данные были успешно отправлены клиентом.Это мой код до сих пор:

//client.c
#include <errno.h>
#include <fcntl.h>

struct values{
 char privateFIFO[14];
 char jobName[14];
 int memRequest;
 int fragmentation;

 int page;


 }input;

 int main ()
 {
   int fda;// write to server
   int fdb; // read to server
   char temp[14];
   int clientID;



    clientID = getpid();

    strcpy(input.privateFIFO, "FIFO_"); //get name of private
    sprintf(temp, "%d", clientID);
    strcat(input.privateFIFO, temp);
    printf("\nFIFO name is: %s", input.privateFIFO);

    printf("Enter the name of the job name: ");
    scanf("%s", &input.jobName);
    printf("\nJob name is: %s\n", input.jobName);

    printf("\nEnter the amount of memory memory request: \n");
    printf("The amount MUST NOT be greater than 4096 or less than 0:   ");
    scanf("%d", &input.memRequest);
    printf("Amount of memory requested:  %d\n", input.memRequest);

    while(input.memRequest <= 0 || input.memRequest > 4096) //Send a Error 
     message if the request is invalid
    {
      printf("\nINVALID REQUEST!!!.\n");
       printf("The amount of request MUST NOT be greater than 4096 or less than 0:   ");
    scanf("%d", &input.memRequest);
}


if ((mkfifo(input.privateFIFO,0666)<0 && errno != EEXIST))
{
   perror("cant create FIFO_to_client");
   exit(-1);
}

if((fda=open("commonFIFO", O_WRONLY))<0)
    printf("can't open fifo to write.");

write(fda, &input, sizeof(input));
printf("\nClient: The Job Name and Memory Request have been sent to the Server and Waiting for the response: ");

if((fdb=open(input.privateFIFO, O_RDONLY))<0)
    printf("\n can’t open FIFO to read.");

read(fdb, &input, sizeof(input));
printf("\nClient: recieved response from Server");
printf("\nThe job needes %d number of frames\n", input.page);
printf("\nThe fragmentation is %d\n", input.fragmentation);
close(fda);
close(fdb);
unlink(input.privateFIFO);
return 0;
 }

Сервер:

// server.c
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>

struct values{
char privateFIFO[14];
char jobName[14];
int memRequest;
int fragmentation;
int page;

};

int main ()
{
  int fda;  // read from client
  int fdb;  // write to client
  //int finish; // lets me know that client is done

 char temp[14]; // buffer hold a character
 int clientNum;
int i; // loop counter
int j; // loop counter
int holder = 0;
int frameNum[16];
int frames[16];
int fragmentation = 0;
int counter = 0;
int page = 0;

//reads the number of clients

printf("\nAssume that in the main memory contain 16 frames\n");
printf("Each frame has 256 bit\n");
printf("How many clients [Min: 3]: ");
scanf("%d", &clientNum);    

struct values input[clientNum];

for (i = 0; i < 16; i++)
{
    frameNum[i] = 0;
    frames[i] = 256;
}


if ((mkfifo("commonFIFO", 0666)<0 && errno !=EEXIST))
{
    perror("can’t create commonFIFO\n");
    exit(-1);
}

if((fda=open("commonFIFO", O_RDONLY))<0)
    printf("can't open fifo to write.");


for(i=0; i<clientNum; i++) // how many job request form client
{
    /* Create the fifos and open them  */
    printf("hello");
    read(fda, &input[i], sizeof(input));
    printf("\nServer: FIFO name is: %s\n", input[i].privateFIFO);

    holder = input[i].memRequest;

    if (holder <= 256)
    {
        frames[counter] = holder;
        fragmentation = 256 - holder;
        frameNum[counter] = counter + 1;
        page = frameNum[counter];
        counter++;
        printf("\nThe fragmentation is %d\n", fragmentation);
        printf("\nThe memory request %d frame(s) in the main memory", page);
    }
    else
    {
        frames[counter] = 256;
        counter =  holder / 256 + 1;
        fragmentation = 256* counter - holder;
        frameNum[counter] = counter;
        page = frameNum[counter];
        printf("\nThe fragmentation is %d\n", fragmentation);
        printf("\nThe memory request %d frame(s) in the main memory\n", page);
        counter++;
    }
    input[i].page = page;
    input[i].fragmentation = fragmentation;

}
for(i=0; i<clientNum; i++) // how many job request form client
{
if ((fdb=open(input[i].privateFIFO,O_WRONLY))<0)
    printf("\n Can't open to read. ");

write(fdb, &input[i], sizeof(input[i]));

close (fdb);


}
printf("\nI am Done! Closing Server!\n");
close(fda);

unlink("commonFIFO");
return 0;

   }

Выход клиента:

-bash-3.2$ ./client2

 FIFO name is: FIFO_3794Enter the name of the job name: job1

 Job name is: job1

 Enter the amount of memory memory request:
 The amount MUST NOT be greater than 4096 or less than 0:   489
 Amount of memory requested:  489

 Client: The Job Name and Memory Request have been sent to the Server and 
 Waiting for the response:

Сервер:

-bash-3.2$ ./server2

 Assume that in the main memory contain 16 frames
 Each frame has 256 bit
 How many clients [Min: 3]: 3

 Server: FIFO name is: FIFO_3794

 The fragmentation is 23

 The memory request 2 frames in the main memory

Сервер не отправил обратно конечный результат клиенту !!!!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...