Linux Process Waiting

LinuxLinuxBeginner
Practice Now

Introduction

In the ancient Empire of Linutopia, ruled by the wise Emperor Forkius Maximus, there was a magnificent system of governance where each decree was processed and executed with impeccable accuracy and timing. The Empire was known for its advanced communications system, built upon the mystical prowess of the signal handlers and the wise Process Oracles.

The background of this Lab revolves around Linutopiaโ€™s practices of processing edicts and ensuring that no task is left unchecked. Your goal is to step into the shoes of a young Process Scribe and master the arcane skills of controlling the wait mechanisms in the Linux system. You must learn how to make processes wait for the completion of others, an art that enables the smooth and ordered execution of Emperor Forkius's decrees.

The tasks will draw you into a captivating scenario where you must ensure that the Emperorโ€™s will is carried out efficiently, honing your skills in the Linux command line using wait, and the signals that govern the running processes.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/ProcessManagementandControlGroup(["`Process Management and Control`"]) linux/ProcessManagementandControlGroup -.-> linux/wait("`Process Waiting`") subgraph Lab Skills linux/wait -.-> lab-271433{{"`Linux Process Waiting`"}} end

Setting up the Ceremony

In this step, you will set up the ceremonial script that the Emperor wishes to execute for the annual Feast of Forks. This event requires the completion of several preparations before the main ceremony can commence.

Create a script named prepare_feast.sh in the ~/project directory with the following content:

#!/bin/bash

echo "Preparing the feast. Please wait..."

## Start the preparations in the background
./decorate_hall.sh &
./cook_feast.sh &

## Wait for preparations to finish
wait

wait_status=$?
if [ $wait_status -eq 0 ]; then
  echo "All preparations completed. The Feast of Forks can commence!"
  ## Run the verify script
  ./verify $wait_status
else
  echo "Error occurred while waiting for preparations to finish. Exit status: $wait_status"
  ## Run the verify script with the error status
  ./verify $wait_status
fi

Make sure the scripts decorate_hall.sh and cook_feast.sh exist, with basic echo commands inside, and ensure they are executable.

Here's an example of what decorate_hall.sh might look like:

#!/bin/bash
echo "Decorating the grand hall for the feast..."
sleep 2
echo "Decoration complete."

Do the same for cook_feast.sh, changing the echoed messages appropriately.

Adding executable permissions

chmod +x prepare_feast.sh
chmod +x decorate_hall.sh
chmod +x cook_feast.sh

Ensure you understand that using wait in prepare_feast.sh pauses the execution of the script until all background processes are completed.

Once the above shell script has been written and configured, run the following command

./prepare_feast.sh 2> error.log

Summary

In this lab, you stepped into the ancient world of Linutopia to practice the arts of process waiting and management, almost as if you were orchestrating the workflows of the imperial court. The lab was designed to familiarize you with the command line skills necessary to use wait effectively and monitor process states, all set within an enticing narrative framework that echoes the complex workings of an empire.

Your journey through the lab should have bolstered your understanding of background processes, the wait command, and process states in Linux. With these new skills, you're now ready to handle multitasking in your own system administration or development tasks, following the practices of the wise Emperor Forkius Maximus.

Other Linux Tutorials you may like