Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Overview Two thieves want to sneak into a room and break into a safe. One thief,

ID: 3715302 • Letter: O

Question

Overview

Two thieves want to sneak into a room and break into a safe. One thief, the lookoutThief, will stay outside of the room and watch (well time) to see if they might get caught. The other thief, the crackingThief will go into the room and try to crack into the safe. The safe has a pre-defined combination, and will report when it is broken into.

The lookoutThief starts both the crackingThief and the safe processes. It tells the OS to send SIGALRM to it NUM_SECS_BEFORE_MUST_GO seconds in the future. Then it waits anxiously for either SIGCHLD (the crackingThief has finished because it got into the safe), or SIGALRM (Forget the safe! We gotta go!)

The safe chooses a random combination. Then it hangs out waiting for either SIG_QUIT (the game is over, stop the process), or SIG_TRY_NEXT_DIGIT (see if the current combination is correct)

The crackingThief gets the process id of the safe from its command line. It does tryNextCombination() to try the next combination by sending SIG_TRY_NEXT_DIGIT to the safeprocess. It then hangs out waiting for either SIG_WRONG_DIGIT (just do tryNextCombination()), SIG_RIGHT_DIGIT (if we have all 3 digits, brag about opening the safe and then quit, else tell how many left to do and do tryNextCombination()), or SIG_QUIT (the game is over, stop the process)

Sample output

Please copy and paste the following:

You will have to write safe.c mostly from scratch.

Include safeBustersHeaders.h and have 5 int global variables for:

should the program still run (initialize to 1)

was the safe opened (initialize to 0)

the first number of the combination

the second number of the combination

the third number of the combination

main() should do

srand(getpid()) (this initializes the random number generator)

Install a simple handler for SIG_QUIT

Install an advance handler for SIG_TRY_NEXT_DIGIT

Initialize all your combination numbers with the expression (rand() % 16) + 1

printf() what the combination is

Hangout in a loop:

After ending the loop, note whether the safe was opened:

Do return(EXIT_SUCCESS)

Your simple SIG_QUIT handler should just set your should still run variable to 0.

Your advanced SIG_TRY_NEXT_DIGIT handler should

See if your first combination number variable is greater than 0. If it is then do computeResponse(address of first number var) and send the int value it returns back to the process that signaled it.

else, if your second combination number variable is greater than 0. If it is then do computeResponse(address of second number var) and send the int value it returns back to the process that signaled it.

else, if your third combination number variable is greater than 0. If it is then do computeResponse(address of third number var) and send the int value it returns back to the process that signaled it. However before sending your signal back to the crackingThief process, see if this value equals SIG_RIGHT_DIGIT. If so, then set your was safe opened variable to 1.

I will just give you the code for computeResponse()

Explanation / Answer

Include safeBustersHeaders.h
int shouldStillRun = 1;

int safeopened = 0;

int count0 = 0;

int count1 = 0;

int count2 = 0;
int main(){
srand(getpid())
}