Using Unix system calls, fork(), wait(), read() and write(), write a C program for integerbasic arithmetics. Your progra

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Using Unix system calls, fork(), wait(), read() and write(), write a C program for integerbasic arithmetics. Your progra

Post by answerhappygod »

Using Unix system calls, fork(), wait(), read() and write(),write a C program for integerbasic arithmetics. Your program shouldfollow the sequential steps, given below.
• Prompts the message "This program performs basicarithmetics",
• Gets in an infinite loop, then
1. Writes the message "Enter an arithmetic statement, e.g., 34 +132 > ",
2. Reads the input line (you can use read(0, line, 255) whereline is a 255-array),
3. Forks, then – parent writes the message "Created a child tomake your operation, waiting" then calls wait() to wait for itschild. – child process calls the function childFunction(char *) andnever returns.
4. The child, through childFunction(char *line),
– writes the message "I am a child working for my parent"
– usessscanf() to convert the input line into an integer, acharacter 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 arithmeticoperation,
– uses sprint() to create an output buffer consisting of n1 opn2 = result. Output example: 13 - 4 = 9
– writes the output buffer to the screen
– calls exit(0)
5. Once the child terminates, the parent checks the returnedstatus 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"
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply