Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the orginal question and code Write a C/C++ program using fork() system call that allows a parent and a child processes to cooperate

This is the orginal question and code

Write a C/C++ program using fork() system call that allows a parent and a child processes to cooperate on carrying some computations. The program should get two (2) numbers from the user of the program. The child process should compute and display the sum and difference of the two numbers; the parent process should multiply and divide the two numbers and display the results. Your program should avoid any exception or interrupt.

My Teacher has given feed back and said

1.The program has a bug double to float conversion

2. It doesnt check for exception &

3.The execution of program creates zombie and an orphan processes

HOW CAN I FIX THESE THREE THINGS ????? MY ORIGINAL CODE IS BELOW

#include #include

int main() {

int num1,num2; puts("Please Type Your First Number: "); scanf("%d",&num1); puts("Please Type Your Second Number : "); scanf("%d",&num2); puts(" Thank You: "); int counter = 0; pid_t pid = fork();

if (pid == 0) { // child process int sum = num1 + num2; int diff = num1 - num2; printf(" The Sum of %d and %d is %d and The Diff is %d",num1,num2,sum,diff); } else if (pid > 0) { // parent process int mul = num1 *num2; float div = num1/(num2*1.0); printf(" The Multiplication of %d and %d is %d and The Division is %f",num1,num2,mul,div); } else { // fork failed puts("fork() failed! "); return 1; }

return 0; }

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_2

Step: 3

blur-text-image_3

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

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions

Question

5. Understand how cultural values influence conflict behavior.

Answered: 1 week ago

Question

e. What do you know about your ethnic background?

Answered: 1 week ago