Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Note: Since Chegg doesn't allow to upload a file, I cannot include prob2. However, you can find a similar problem online. 2) Shell Scripting. File

image text in transcribed

Note: Since Chegg doesn't allow to upload a file, I cannot include prob2. However, you can find a similar problem online.

2) Shell Scripting. File prob2 is an executable program and compiled without "-9" flag. This program is run with the format of $ ./prob2 please use: prob2 guess_number Inside the program, there is a secret key that is changed each second and is between 0 and 2147483647. You will write a shell script "prob2.sh to find a correct secret key within a second. Specifically, the command line argument "guess_number" is compared with the secret key, and if they are equal, the program returns 0 and prints "Yes, your guess is correct! secret = xxx, for example $ prob2 12345 Yes, your guess is correct! secret = 12345 $ echo $? If the guess_number is larger than the secret key, the program returns 1, for example, $ prob2 2147483647 $ echo $? If the guess_number is smaller than the secret key, the program returns 2, for example, $ prob20 $ echo $? Please write a shell script, named "prob2.sh, to find the correct secret key within a second. Since the secret key will be changing after a second, your script needs to consider an efficient searching algorithm. Moreover, even for an efficient searching algorithm, the secret key could change in the middle of running your script, and thus the search fails. But your shell script needs to have a high chance to find the secret key for each run. If it fails, please indicate this after running your script. Here are expected running results: $ prob2.sh Yes, your guess is correct! secret = 757547896 Found: 757547896 $ prob2.sh Yes, your guess is correct! secret = 444454915 Found: 444454915 $ prob2.sh Yes, your guess is correct! secret = 1215069295 Found: 1215069295 $ prob2.sh Yes, your guess is correct! secret = 1989311423 Found: 1989311423 $ prob2.sh Yes, your guess is correct! secret = 1687063760 Found: 1687063760 $ prob2.sh NOT found $ prob2.sh Yes, your guess is correct! secret = 1086411056 Found: 1086411056 2) Shell Scripting. File prob2 is an executable program and compiled without "-9" flag. This program is run with the format of $ ./prob2 please use: prob2 guess_number Inside the program, there is a secret key that is changed each second and is between 0 and 2147483647. You will write a shell script "prob2.sh to find a correct secret key within a second. Specifically, the command line argument "guess_number" is compared with the secret key, and if they are equal, the program returns 0 and prints "Yes, your guess is correct! secret = xxx, for example $ prob2 12345 Yes, your guess is correct! secret = 12345 $ echo $? If the guess_number is larger than the secret key, the program returns 1, for example, $ prob2 2147483647 $ echo $? If the guess_number is smaller than the secret key, the program returns 2, for example, $ prob20 $ echo $? Please write a shell script, named "prob2.sh, to find the correct secret key within a second. Since the secret key will be changing after a second, your script needs to consider an efficient searching algorithm. Moreover, even for an efficient searching algorithm, the secret key could change in the middle of running your script, and thus the search fails. But your shell script needs to have a high chance to find the secret key for each run. If it fails, please indicate this after running your script. Here are expected running results: $ prob2.sh Yes, your guess is correct! secret = 757547896 Found: 757547896 $ prob2.sh Yes, your guess is correct! secret = 444454915 Found: 444454915 $ prob2.sh Yes, your guess is correct! secret = 1215069295 Found: 1215069295 $ prob2.sh Yes, your guess is correct! secret = 1989311423 Found: 1989311423 $ prob2.sh Yes, your guess is correct! secret = 1687063760 Found: 1687063760 $ prob2.sh NOT found $ prob2.sh Yes, your guess is correct! secret = 1086411056 Found: 1086411056

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

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions