Soru

Zorluk: OrtaBasic Scripting Languages and Constructs

A system administrator is reviewing a Bash script (.sh) designed to monitor a server maintenance task on a Linux workstation. The script must repeatedly check the status of a background process every 30 seconds and continue checking as long as the process state remains active. Which of the following basic scripting constructs should be used to repeatedly execute the status check until the process finishes?

  1. A while loop constructCevap
  2. B
    A for loop construct
  3. C
    An if...else conditional statement
  4. D
    An environment variable declaration

Cevap

A while loop construct is used to repeatedly execute commands as long as a specified condition remains true.
A while loop construct is designed to test a conditional expression and execute a block of code repeatedly as long as that condition evaluates to true. In this scenario, the process status check must run indefinitely at 30-second intervals until the background process completes, making a while loop the correct choice.

Adım Adım Çözüm

1
Identify the scripting requirement from the scenario.
The requirement calls for repeatedly performing a status check as long as an active process condition is true.
Choosing the correct control construct depends on whether execution flow relies on single-pass branching, fixed iteration, or indefinite condition-based looping.
2
Evaluate the behavior of a while loop construct.
A while loop tests a condition prior to each iteration and continues repeating the enclosed commands until the condition evaluates to false.
This matches the requirement to check process status continuously for an unknown duration until completion.

Anahtar Kavram

Scripting Control Constructs (While Loop vs. For Loop vs. Conditional Branching)
Bu soruyu puanla