Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use C and system calls. Using Unix system calls, fork(), wait(), read() and write(), write a C program for integer- basic arithmetics. Your program should
Use C and system calls.
Using Unix system calls, fork(), wait(), read() and write(), write a C program for integer- basic arithmetics. Your program should follow the sequential steps, given below. Prompts the message "This program makes simple arithmetics", Gets in an infinite loop then I. Writes the message "Enter an arithmetic statement, e.g., 34 + 132 >' 2. Reads the whole input line, 3. Forks and the parent writes the message "Created a child to make your operation, wait- ing" then calls wait) to wait for its child - the child process calls the function childFunction(char *) and never returns 4. The child, through childFunction(char *line), - writes the message "I am a child working for my parent" - uses sscanf) to covert the input line into an integer, a character and an integer, respectively in case of wrong statement, the child calls exit(50) - in case of division by zero, the child calls exit(100) - in case of a wrong op the child calls exit(200) - otherwise, it performs the appropriate arithmetic operation, -uses sprint() to create an output buffer consisting of nl op n2 = result, - writes the output bufferto the screen calls exit(0) 5. Once the child terminates, the parent checks the returned status value and if it is 50, 100 or 200, writes "Wrong statement", "Division by zero" or "Wrong operator", respectively. 6. The parent goes back to 1. Important: . All reads/writes must be done using read(/write() You can use the returned value of sscanf() for detecting a "Wrong statement" Using Unix system calls, fork(), wait(), read() and write(), write a C program for integer- basic arithmetics. Your program should follow the sequential steps, given below. Prompts the message "This program makes simple arithmetics", Gets in an infinite loop then I. Writes the message "Enter an arithmetic statement, e.g., 34 + 132 >' 2. Reads the whole input line, 3. Forks and the parent writes the message "Created a child to make your operation, wait- ing" then calls wait) to wait for its child - the child process calls the function childFunction(char *) and never returns 4. The child, through childFunction(char *line), - writes the message "I am a child working for my parent" - uses sscanf) to covert the input line into an integer, a character and an integer, respectively in case of wrong statement, the child calls exit(50) - in case of division by zero, the child calls exit(100) - in case of a wrong op the child calls exit(200) - otherwise, it performs the appropriate arithmetic operation, -uses sprint() to create an output buffer consisting of nl op n2 = result, - writes the output bufferto the screen calls exit(0) 5. Once the child terminates, the parent checks the returned status value and if it is 50, 100 or 200, writes "Wrong statement", "Division by zero" or "Wrong operator", respectively. 6. The parent goes back to 1. Important: . All reads/writes must be done using read(/write() You can use the returned value of sscanf() for detecting a "Wrong statementStep 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