Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Lock Company You are tasked with writing a program that will manage storage lockers from a terminal program (locker). Each locker is represented as

The Lock Company

You are tasked with writing a program that will manage storage lockers from a terminal program (locker). Each locker is represented as a process in the system. Signals can be sent to the process to change the state of the locker outside of the management program.

A locker process is made up of:

Process ID (pid) : (unique to process creation)

Locker ID : Creation order, Unsigned integer, starts at 1

User Id : Unsigned integer

Locked/Unlocked state

Owned/Free state

Two signal handlers (SIGUSR1 and SIGUSR2)

A locker can be in 4 states, {Locked, Free}, {Locked, Owned}, {Unlocked, Free} and {Unlocked, Owned} states. Free lockers are kept in a queue for reuse. Your program should also report on how many processes are unlocked and free so your management program can prevent them from being vandalized.

Each locker needs to handle a SIGUSR1 and SIGUSR2 signals. SIGUSR1 locks the locker and SIGUSR2 unlocks the locker.

When a locker is damaged or needs to be repaired/recycled your program will receive a request to decomission a locker (DELETE). You should not utilise SIGTERM to terminate a locker. This should be part of your protocol to decomission a locker.

Please note! If heap data has been allocated then newly spawned lockers should immediately free this upon execution.

The list of commands and arguments your program can receive:

CREATE - Creates a locker DELETE - Decommissions a locker QUERY - Queries a locker and retrieves information QUERYALL - Queries all lockers and retrieve their information LOCK - Locks a locker UNLOCK - Unlocks a locker ATTACH - Adds an owner to a locker, gets locker at head of the queue DETACH - Removes an owner from a locker QUIT - Deletes all lockers and quits the program 

The default states of a locker when created:

Locked

No Owner (Detached)

When the management process queries a locker it will print out information in this form (QUERY or QUERYALL):

Locker ID: Lock Status: Owner: 

Output format for ATTACH:

Locker Owned By 

Output format for DETACH:

Locker Unowned 

Output format for LOCK and UNLOCK:

Locker 

Output format for CREATE:

New Locker Created: 

Output format for DELETE:

Locker Removed 

Important:

You will have to define a simple communication protocol to communicate between these prcesses. This can be text messages over the pipe and parsing them.

In the event that you cannot create a new locker, your program needs to output:

Cannot Build Locker 

In the event that a command utilises a locker id that does not exist, your program needs to output:

Locker Does Not Exist 

If Attach is called and no lockers are unowned your program needs to output:

No Lockers Available 

Recommended functions to use: pipe(), kill(), signal()/sigaction, fork(), wait()/waitpid() and dynamic memory functions. Potentially bitfields could be useful for the protocol.

Assumptions/Clarifications:

If you attempt to lock a locked locker or unlock an unlocked locker, you will just need to relay the status regardless. You do not have to output that the operation did nothing.

Owner id's are just inputted by your application and can be completely arbitrary but you can assume the maximum owner id is 255.

When a DELETE operation occurs, unless the locker does not exist, it should remove the locker, regardless if it is owned by someone.

QUIT should clean up and terminate all locker processes and quit without any output.

You will need to ensure that you can create two way communication between processes.

When executing query all, ordering is based on locker id order (Ascending)

Example:

Example 1 Create Locker:

CREATE New Locker Created: 1 

Example 2 Query Locker 1:

CREATE New Locker Created: 1 QUERY 1 Locker ID: 1 Lock Status: locked Owner: unowned 

Example 3 Unlock/Lock:

CREATE New Locker Created: 1 QUERY 1 Locker ID: 1 Lock Status: locked Owner: unowned UNLOCK 1 Locker 1 Unlocked QUERY 1 Locker ID: 1 Lock Status: unlocked Owner: unowned LOCK 1 Locker 1 Locked QUERY 1 Locker ID: 1 Lock Status: locked Owner: unowned 

Example 4 Attach:

CREATE New Locker Created: 1 CREATE New Locker Created: 2 ATTACH 67 Locker 1 Owned By 67 ATTACH 20 Locker 2 Owned By 20 

Example 5 DELETE:

CREATE New Locker Created: 1 DELETE 1 Locker 1 Removed 

Example 6 QUERALL example:

CREATE New Locker Created: 1 CREATE New Locker Created: 2 CREATE New Locker Created: 3 QUERYALL Locker ID: 1 Lock Status: locked Owner: unowned Locker ID: 2 Lock Status: locked Owner: unowned Locker ID: 3 Lock Status: locked Owner: unowned 

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

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago