serverFifo.pipeDescriptor = returnedValue; while(true) { cout << "\ncmd" <<endl;#ifdef DEBUG cout <<"PIPE of server: " << serverFifo.getName() <<endl;#endif numberOfBytes = read(fileno(stdin), buffer.message, PIPE_BUF);#ifdef DEBUG cout <<"what you write: "<<buffer.message<<endl;#endif if (!strncmp("exit", buffer.message, numberOfBytes - 1)) break; write(serverFifo.pipeDescriptor,(char *) &buffer, sizeof(buffer)); returnedValue = open(myFifo.getName(), O_RDONLY | O_NDELAY); if(returnedValue == -1) { perror(myFifo.getName()); return 1; } myFifo.pipeDescriptor = returnedValue; readOK = 0; while (readOK != 1) { if((numberOfBytes = read(myFifo.pipeDescriptor, buffer.message, PIPE_BUF)) > 0) { write(fileno(stdout), buffer.message, numberOfBytes); memset(buffer.message,0x0,PIPE_BUF); readOK=1; } } myFifo.closePipe(); } serverFifo.closePipe(); return 1;}Agora a implementacao de nossa classe#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <string.h>#include <linux/limits.h>#include <stdlib.h>#include <iostream>#include <cstdio>#include <fstream>#include <errno.h>using namespace std;typedef struct dataSet{ char name[255]; char path[255]; char message[PIPE_BUF];}data;class FIFO{ private: data info; public: int pipeDescriptor; char* getName(); void setName(char*); char* getPath(); void setPath(char*); char* getMessage(); void writeMessage(char*); void closePipe(); int writeToPipe(FIFO&); int readFromPipe(FIFO&);};char* FIFO::getName(){ return info.name;}void FIFO::setName(char * nameToSet){ strcpy(info.name,nameToSet);}char* FIFO::getPath(){ return info.path;}void FIFO::setPath(char *pathToSet){ strcpy(info.path, pathToSet);}char* FIFO::getMessage(){ return info.message;}void FIFO::writeMessage(char *messageToWrite){ strcpy(info.message, messageToWrite);}int FIFO::writeToPipe(FIFO& pipeToWrite){ FILE * result; int readFromFile, numberOfBytes, popenIsOk; char buffer[PIPE_BUF], stringBuff[PIPE_BUF];#ifdef DEBUG cout <<"what will be the command to sheel: " << getMessage()<<endl;#endif result = popen(getMessage(), "r"); if(!result) {#ifdef DEBUG cout <<"result is null" << endl; perror("errot in open file");#endif strcpy(stringBuff,"Command not found"); write(pipeToWrite.pipeDescriptor,stringBuff,strlen(stringBuff)+1); return -1; } popenIsOk=0; while(popenIsOk!=1) { if ((numberOfBytes = read(fileno(result), buffer, PIPE_BUF))>0) { strcpy(stringBuff,buffer); write(pipeToWrite.pipeDescriptor,stringBuff,strlen(stringBuff)+1); memset(buffer, 0x0, PIPE_BUF);#ifdef DEBUG cout <<"what will be written to client: " << stringBuff << endl;#endif popenIsOk=1; } } pclose(result);}int FIFO::readFromPipe(FIFO& pipe){ int returnedValue; data buffer; returnedValue = read(pipeDescriptor, (char *) &buffer, sizeof(buffer)); if(returnedValue <=0 ) return returnedValue; else { writeMessage(buffer.message); pipe.setName(buffer.name); } return returnedValue;}void FIFO::closePipe(){ close(pipeDescriptor);}Agora vamos ao nosso MakefileCC:=g++all:PipeServer ClientPipeServer:main.cpp fifo_header.h $(CC) -o PipeServer main.cppClient:client.cpp fifo_header.h $(CC) -o Client client.cppDebug: main.cpp client.cpp fifo_header.h $(CC) -D DEBUG -o PipeServer main.cpp $(CC) -D DEBUG -o Client client.cppComandos necessarios para compilar e rodar:Para compilar os dois programas em modo normal: Comando: make allPara executar:Comando para Rodar o Server: ./PipeServer FIFO /home/eduardo/Documents/programas/FIFOOnde: FIFO e o Nome da PIPE a ser Criada /home/eduardo/Documents/programas/FIFO: Caminho da Pasta onde ela vai ser criadaComando para Rodar o cliente: ./client FIFO /home/eduardo/Documents/programas/FIFOFIFO e o Nome da PIPE criada pelo server /home/eduardo/Documents/programas/FIFO: Caminho da Pasta onde ela foi criadaComo o Server roda em BackGround, se voce desejar para o server de o comando: ./PipeServer StopPara parar o cliente apenas digite exitPara o dois programas em modo de DEBUGcomando para compilar: make DebugPara rodar o server(agora ele nao roda em BackGround Ctrl+C se desejar parar o server): ./PipeServer Debug /home/eduardo/Documents/programas/FIFOPara rodar o cliente: ./client Debug /home/eduardo/Documents/programas/FIFOBons Testes!!!!