The Lock Company You are tasked with writing a program that will manage storage
ID: 3841832 • Letter: T
Question
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:
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):
Output format for ATTACH:
Output format for DETACH:
Output format for LOCK and UNLOCK:
Output format for CREATE:
Output format for DELETE:
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:
In the event that a command utilises a locker id that does not exist, your program needs to output:
If Attach is called and no lockers are unowned your program needs to output:
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:
Example 2 Query Locker 1:
Example 3 Unlock/Lock:
Example 4 Attach:
Example 5 DELETE:
Example 6 QUERALL example:
Explanation / Answer
Example 1 Create Locker:
Example 2 Query Locker 1:
Example 3 Unlock/Lock:
Example 4 Attach:
Example 5 DELETE:
Example 6 QUERALL example:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.