1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
svlad2 [7]
3 years ago
11

Write a client program that writes a struct with a privateFIFO name (call it FIFO_XXXX, where XXXX is the pid that you got from

the getpid( ) function) to the server. Have the server read the privateFIFO name and write a message back to the client. Read the message and print it on the client side
Computers and Technology
1 answer:
ivann1987 [24]3 years ago
3 0

Answer:

client code:

#include <stdio.h>

#include <fcntl.h>

#include <sys/stat.h>

#include <sys/types.h>

#include <unistd.h>

#include <stdlib.h>

#include <string.h>

int main (void)

{

 struct values

 {

   char privateFIFO[14];

   int intbuff;

 }input;

 int fda;  // common FIFO to read to write to server

 int fdb;      // Private FIFO to read from server

 int clientID;

 int retbuff;

 char temp[14];

 clientID = getpid();

 strcpy(input.privateFIFO, "FIFO_");

 sprintf(temp, "%d", clientID);

 strcat(input.privateFIFO, temp);

 printf("\nFIFO name is %s", input.privateFIFO);

 // Open common FIFO to write to server

 if((fda=open("FIFO_to_server", O_WRONLY))<0)

    printf("cant open fifo to write");

 write(fda, &input, sizeof(input));    // write the struct to the server

 close(fda);

 // Open private FIFO to read

 if((fdb=open(input.privateFIFO, O_RDONLY))<0)

    read(fdb, &retbuff, sizeof(retbuff));

 printf("\nAll done\n");

 close(fdb);

}

server code:

#include <stdio.h>

#include <errno.h>

#include <fcntl.h>

#include <sys/stat.h>

#include <sys/types.h>

#include <unistd.h>

#include <stdlib.h>

#include <string.h>

struct values

 {

   char privateFIFO[14];

   int intbuff;

 }input;

int main (void)

{

 int fda;  //common FIFO to read from client

 int fdb;  //private FIFO to write to client

 int retbuff;

 int output;

// create the common FIFO  

 if ((mkfifo("FIFO_to_server",0666)<0 && errno != EEXIST))

       {

       perror("cant create FIFO_to_server");

       exit(-1);

}

// open the common FIFO

 if((fda=open("FIFO_to_server", O_RDONLY))<0)

    printf("cant open fifo to write");

output = read(fda, &input, sizeof(input));

// create the private FIFO

 if ((mkfifo(input.privateFIFO, 0666)<0 && errno != EEXIST))

 {

   perror("cant create privateFIFO_to_server");

   exit(-1);

 }

 printf("Private FIFO received from the client and sent back from server is: %d", output);

 //open private FIFO to write to client

if((fdb=open(input.privateFIFO, O_WRONLY))<0)

   printf("cant open fifo to read");

 write(fdb, &retbuff, sizeof(retbuff));

 close(fda);

 unlink("FIFO_to_server");

 close(fdb);

 unlink(input.privateFIFO);

}

Explanation:

You might be interested in
Who is the father of computer​
r-ruslan [8.4K]

charles babbage is the father of computer's

3 0
3 years ago
Read 2 more answers
You are going to write a program for Computer test which will read 10 multiple choice questions from a file, order them randomly
sweet-ann [11.9K]

Answer:

Code is too large , i attached a source file below and also a text file from where i get Questions

Explanation:

6 0
3 years ago
When workers demonstrate patience, are able to manage there emotions, and get along with other employees, which skills are being
LenKa [72]
The skill thar is being displayed I thing is being outgoing and loyal
6 0
3 years ago
Read 2 more answers
Marx and engels identified two social classes: the ______ who possess the means of production and ______ who must do all the wor
Morgarella [4.7K]

Marx and Engels identified two social classes: the exploiters who possess the means of production and exploited  who must do all the work.

<h3>What is a Social class?</h3>

A social class is known to be a kind of a grouping of people and it is one that is made where people are said to be shared into a set of hierarchical social stages  or groups.

Note that the most common are the upper, middle and lower classes. Membership in a social class is seen to be based on  or dependent on education, wealth, occupation, and others.

Hence, Marx and Engels identified two social classes: the exploiterswho possess the means of production and exploited  who must do all the work.

Learn more about social classes from

brainly.com/question/1065123

#SPJ1

8 0
2 years ago
write c++programs for the following problem: Let the user enter two numbers and display which is greater. please help!
zmey [24]

Program to display greater number:


#include <iostream>                     <em>// Needed to perform IO operations    </em>

#include<conio.h>                     <em>  // header file</em>

using namespace std;  


int main()                                        //start of the program

{

   int a , b =0;                         //initialising the two integer variable

   cout<< "Enter first number"<<endl;  

    cin >> a;                                     //user's first number

    cout<< "Enter second number"<<endl;

    cin >> b;                                    //user's second number

     if (a>b)                       //comparing the two integers input by user

  cout<<  a << "is greater than" << b;    //display the greater number

    else

  cout<<  b << "is greater than" << a;                

return 0;                                                               // exist

}


     

3 0
3 years ago
Other questions:
  • a supermarket having a sale on canned foods' the sale includes 12 cans of soup for 10.65 what is the unit price per can of soup
    6·2 answers
  • A _____ is an electronic path over which data can travel.
    15·1 answer
  • Mica's creating his web page with a software that is free of charge for the first month. If he likes the program, he will have t
    8·2 answers
  • What is the difference between hardware and software?
    9·1 answer
  • Kelly is a college sophomore majoring in computer science. She is interested in gaining exposure to the most useful and current
    13·1 answer
  • Assume that strikeCounter has already been declared to be a "pointer to int". Assume further that strikeCounter has been initial
    5·1 answer
  • Write a C++ program that produces a simple personalized adventure game called Lost Fortune about a band of explorers that finds
    12·1 answer
  • The name of a .java file should ______________________________. Always match the name of the Class inside Should always start wi
    9·1 answer
  • 1. The supervisory software of a computer is called _____ (a) operating system (b) high – level language (c) transistor
    5·1 answer
  • Write the technical terms for the following statements: The repeated working capacity of computer.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!