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
What is authentication?
Savatey [412]

Answer:

C

Explanation:

I believe that's the answer if it's not sorry

8 0
3 years ago
Trisha is looking for a new table style. What is the fastest way for her to preview how different styles in the gallery would lo
Elena-2011 [213]

Answer: The correct answer is to hover the cursor over the different styles in the gallery.

Explanation: The fastest way to preview the different styles in the style gallery is to hover the cursor over each style. This will preview the style, without making the permanent change so that you can see how it looks without changing to each individual style.

4 0
3 years ago
The mac group does not replace the primary functions of eocs or other dispatch organizations. True or False
Oxana [17]

Answer:

TRUE

Explanation:

MAC - multi-agency coordination is a group of executives or administrators that have the authority to control agency funds or resources while EOCs -  Emergency operation centers are in charge of carrying out of emergency tasks that requires preparedness or disasters, they ensure that work continues even in case of emergency and disasters.

7 0
3 years ago
Billy used to take care of his laptop. However, one day he lost his laptop. He lost all his data, and there was no way to retrie
Bad White [126]

Answer: D. He did not create a back up of his data.

Explanation: He lost his data, so he did not back it up in case he lost his laptop.

6 0
3 years ago
Characteristics of successful entrepreneurs include
crimeas [40]
The answer would be A because grit means to fight hard to get what you want. Submission would be to give in to pressure and give up. Self-importance would be to only focus on yourself and no one else. A short attention span would not work out for you because you get distracted easily.
8 0
3 years ago
Other questions:
  • You can use ???? a to test tread wear on your tires
    14·2 answers
  • If an author is creating a reference list and wants the second and succeeding lines indented for a reference, they should select
    13·2 answers
  • Which statement best describes what happen to the temoporary working memory (RAM) of a computer when it shut down
    12·2 answers
  • The command-line interface tells a user that it's ready to receive commands by displaying a specific set of characters called a(
    12·1 answer
  • Which of the following Web sites would be MOST credible?
    6·1 answer
  • A reflexive pronoun is a pronoun
    6·1 answer
  • Hi, please help me complete my Database Development 2 hw by completing what should been done from the document and show the code
    11·1 answer
  • Whenever you press a key, click the mouse or start an application, you're sending instructions tow
    9·1 answer
  • H e l p ASAP plz <br> and thanks
    9·1 answer
  • Which of the following is not a bus type A. Address bus B. Data bus C. Memory bus D. Control bus ​
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!