Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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 1. 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 convert 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 1. 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 convert 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago