Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview: 1. You are to write two programs, interface and db. After initialization, interface will use the fork system call and an exec system call

Overview:

1. You are to write two programs, interface and db. After initialization, interface will use the fork system call and an exec system call to start the execution of db. Interface will accept commands from the console and send them to db for execution. After executing the command, db will send the output to interface for display on the console.

2. Pipes: interface will need to create the pipes to be used for communication between itself and db prior to doing the fork. Use two pipes, one for sending commands to db and one for sending the response to interface.

3. Interface: In addition to tasks described elsewhere, interface must pass the pipe file descriptor values to db. Use the arguments on the exec command for this purpose. Interface should also detect the final exit status of db and display an appropriate message.

4. DB: When db initializes, it must do two things before entering its loop accepting commands. First, it must initialize an array of structures (records) using the data in a local file called accountData.

This file must contain data for at least twelve records. Second, it should display the contents of the array so it is easy to verify that the initialization occurred correctly. The records will keep track of a set of bank accounts. Each structure in the array is to consist of the following fields:

id: this is the identifier of the account. It is to be a long integer.

checkNumber: the check (or transaction) number (int).

amount: The amount withdrawn from the account (float).

date: The date of the transaction(char).

You are to create and use a typedef for the record structure.

5. accountData: each line of this ASCII file is to contain the data for one record of the array of structures. Each line is expected to be in the form:

id checkNumber date amount

where a single space is used as a delimiter.

6. Makefile: Write a makefile to control the compilation of your programs.

7.Commands: Four commands must be processed:

account,

This is to compute the total value of all transactions identified by the label .

list

This will list all of the transactions ordered first by id and then for each id ordered by increasing date.

(Note: it is assumed that some sorting will have to be performed; the elements must be initialized in a different order.)

date,

This is to compute the total value of all transactions that occurred on the given date.

exit

After processing this command, db should terminate in a normal manner. After detecting the termination of db, interface should print relevant information and exit normally.

8. System calls: You should view this exercise as an opportunity to try out various system calls. Detailed documentation of the system calls can be found in the associated man pages. At a minimum, you are expected to use the following system calls: fork, some type of exec call (such as execve), pipe, read, write, exit, waitpid, close. In addition your code is to check the response from the system calls for errors, display an appropriate error message and take appropriate action. In many cases that action may be just to call exit with a unique number selected.

9. Readability: Your program must be written using good C programming conventions:

Variable names and function names should be descriptive of what they represent.

Use indentation to show the structure of the program. Typically this means using indentation with for, while, do-while, if, and switchstatements as well as indenting the body of functions. Indentation should show the nesting level of the statements involved.

Include some in-line documentation to give a high level view of what the program and groups of statements is/are doing.

Sample output:

element[0]: id = 1234567, check Number: 102, date: 08/11/14, amount: 4.00

element[1]: id = 1234567, check Number: 101, date: 08/14/14, amount: 14.00

element[2]: id = 3456787,check Number: 9873, date: 08/30/14, amount: 100.00

element[3]: id = 1234567, check Number: 100, date: 08/16/14, amount: 35.00

element[4]: id = 3456787,check Number: 9874, date: 09/30/14, amount: 4.00

element[5]: id = 12345, check Number: 1010, date: 09/01/14, amount: 34.00

element[6]: id = 1001001, check Number: 905, date: 08/14/14, amount: 9.00

element[7]: id = 1001001, check Number: 903, date: 08/30/14, amount: 11.00

element[8]: id = 12345,check Number: 1001, date: 09/14/14, amount: 16.00

element[9]: id = 12345, check Number: 1111, date: 08/24/14, amount: 2.00

element[10]: id = 1234, check Number: 1112, date: 08/31/14, amount: 44.00

element[11]: id = 1001001, check Number: 902, date: 09/25/14, amount: 19.00

Input command (account,id | list| date,mm/dd/yy | exit):

account,1001001

response: Total for account 1001001: 39.00

Input command (account,id | list| date,mm/dd/yy | exit):

date,08/14/14

response: Total on date 08/14/14: 23.00

Input command (account,id | list| date,mm/dd/yy | exit):

account,1234567

response: Total for account 1234567: 53.00

Input command (account,id | list| date,mm/dd/yy | exit):

exit

response: db complete.

interface: child process (212) completed.

interface: child process exit status = 0.

interface: Complete.

Hints:

Some of the library string functions may be useful: strchr, strcmp, strncmp, strncpy.

In the end, you should have (.c and .h files), makefile, and data file (accountData).

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 Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago