Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In an online banking application, the home process creates a shared memory which has a structure of: struct shared { char sel [ 1 0
In an online banking application, the home process creates a shared memory which has a structure of:
struct shared
char sel;
int b;
;
The process then creates a pipe. Then it prompts input space for users and provides them to select options of their preferences according to the data given below.
Provide Your Input from Given Options:
Type a to Add Money
Type w to Withdraw Money
Type c to Check Balance
After reading selection from user input, the process stores the user input in the sel and sets b of structure shared where sel represents users selected task from the application and b represents current balance. Then it prints the selection as Your selection: selection and sends the data using shared memory and prints about the selection of the user.
After that, home is interrupted and another process which can be denoted by process opr which is a child process of home. Process opr receives and reads data from the shared memory and according to the user input data it executes some operations,
If user input is a then, it provides users an input space to add money and after users enter the amount to be added it adds the amount with the current balance which is stored in b field of structure shared if the amount entered to be added by the user is a positive value greater than After successful addition, it prints the acknowledgement of the operation and updated balance after addition. If the entered amount by the user is less than or equal then it will print Adding failed, Invalid amount
If user input is w then, it provides users an input space to withdraw money and after users enter the amount to be withdrawn it withdraws the amount from the current balance which is stored in b field of structure shared if the amount entered to be withdrawn by the user is less than the current balance and a positive value greater than After successful withdrawal, it prints the acknowledgement of the operation and updated balance after withdrawal. If the entered amount by the user is less than or equal or it is less than the current balance then it will print Withdrawal failed, Invalid amount
If user input is c then, it prints the current balance which is stored in b field of structure shared.
For any other inputs opr process prints Invalid selection
Finally before termination the process opr writes Thank you for using in the pipe and it terminates.
After the termination of its child opr, process home continues and reads the data from the pipe which was written by its child process opr and prints it Then it terminates by removing the shared memory.
Provide a proper solution by executing two cooperating processes according to the flow of processes described in the scenario given above, ensuring proper communication between processes using shared memory.
Sample Output in the Terminal:
Execution Command in Terminal: p
Provide Your Input From Given Options:
Type a to Add Money
Type w to Withdraw Money
Type c to Check Balance
a
Your selection: a
Enter amount to be added:
Balance added successfully
Updated balance after addition:
Thank you for using
Execution Command in Terminal: p
Provide Your Input From Given Options:
Type a to Add Money
Type w to Withdraw Money
Type c to Check Balance
a
Your selection: a
Enter amount to be added:
Adding failed, Invalid amount
Thank you for using
Execution Command in Terminal: p
Provide Your Input From Given Options:
Type a to Add Money
Type w to Withdraw Money
Type c to Check Balance
w
Your selection: w
Enter amount to be withdrawn:
Balance withdrawn successfully
Updated balance after withdrawal:
Thank you for using
Execution Command in Terminal: p
Provide Your Input From Given Options:
Type a to Add Money
Type w to Withdraw Money
Type c to Check Balance
w
Your selection: w
Enter amount to be withdrawn:
Withdrawal failed, Invalid amount
Thank you for using
Execution Command in Terminal: p
Provide Your Input From Given Options:
Type a to Add Money
Type w to Withdraw Money
Type c to Check Balance
c
Your selection: c
Your current balance is:
Thank you for using
Execution Command in Terminal: p
Provide Your Input From Given Options:
Type a to Add Money
Type w to Withdraw Money
Type c to Check Balance
o
Your selection: o
Invalid selection
Thank you for using
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