Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include #include #include #include #include int main ( int argc, char * * argv ) { / * * * * * *
#include
#include
#include
#include
#include
#include
#include
int mainint argc, char argv
write code for the main process that will establish
the communication channel between cleint and server using
pipes
pidt pid;
int fd;
Create pipe
if pipefd
perrorpipe;
exitEXITFAILURE;
pid fork;
if pid
perrorFork failed
;
exitEXITFAILURE;
if pid Child process server
closefd; Close write end in child
serverfd fd;
exitEXITSUCCESS;
else Parent process client
closefd; Close read end in parent
clientfd fd;
waitNULL; Wait for child process to finish
return ;
#include
#include
#include
#include
#include
#include
#include
void clientint readfd, int writefd
char bufMAXBUFF;
sizet len;
write client code to be used by the parent process
implement client functionality
while
Read expression from stdin
printfEnter expression: ;
fgetsbuf MAXBUFF, stdin;
Check for termination condition
if strcmpbuf "END
Send termination signal to server
writewritefd "END", ;
break;
Send expression to server
writewritefd buf, strlenbuf;
Read result from server
readreadfd buf, MAXBUFF;
printfRESULT: s buf;
Close file descriptors
closereadfd;
closewritefd;
#include
#include
#include
#include
#include
#include
#include
void serverint readfd, int writefd
write server code to be used by the child process
char bufMAXBUFF;
sizet len;
Implement server functionlity here
while
Read expression from client
readreadfd buf, MAXBUFF;
Check for termination signal
if strcmpbuf "END"
break;
Evaluate expression
double result calculatebuf;
Convert result to string and send to client
sprintfbuff
result;
writewritefd buf, strlenbuf;
Close file descriptors
closereadfd;
closewritefd;
#include
#include
#include
#include
#include
#include
#include
double calculatechar buf
Implement the expression evaluation functionality which
will be invoked by the server whenever required.
double operands;
char op;
int oprnInd ;
double result ;
implement expression evaluation functionality here
char token strtokbuf;
while token NULL
if sscanftokenlf &operandsoprnInd
oprnInd;
else
strcpyop token; Corrected variable name from 'ops' to op
token strtokNULL;
Perform calculation based on BODMAS rule
result operands;
int i;
for i ; i oprnInd; i
if strcmpop i
result operandsi ;
else if strcmpop i
result operandsi ;
else if strcmpop i
result operandsi ;
else if strcmpop i
result operandsi ;
else if strcmpop i
result intresult intoperandsi ;
return result;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started