Skip to content

Latest commit

 

History

History
112 lines (70 loc) · 2.56 KB

File metadata and controls

112 lines (70 loc) · 2.56 KB

Job Control in Linux

Introduction

In this lesson we will learn how to manage processes in Linux. We will learn how to run processes in the background, how to pause and resume them, and how to run them in the foreground again.

Prerequisites

Exercises

To begin the exercise, ensure you have python3 installed and download the mock script that mimics a robot driver program.

wget https://raw.githubusercontent.com/nevalsar/mrsd-practice-git/main/autonomous-robot-mock.py -O robot-driver.py

You also need to ensure that the script is executable by setting executable permissions.

chmod +x robot-driver.py

Test that you're able to execute the script by running it.

./robot-driver.py 5

Running processes in the background

Using & at the end of the command

  1. Run the sleep command in the background by appending & at the end of the command

    ./robot-driver.py 10 &

    You will notice that the terminal is not blocked and you can run other commands.

  2. List the jobs running in the background to verify

    jobs

Using Ctrl + Z

  1. Run a command in the foreground

    ./robot-driver.py 10

    You will notice that the terminal is blocked by the process running in foreground and you cannot run other commands.

  2. Move the foreground command to background by pressing Ctrl + Z

    You will notice that the terminal is not blocked anymore and you can run other commands.

  3. List the jobs running in the background to verify

    jobs

Moving a background process to the foreground

  1. Run a command in the background by appending & at the end of the command

    ./robot-driver.py 10 &
  2. Move the process to foreground using fg:

    fg

    You will notice that now the terminal is blocked by the process running in foreground and you cannot run other commands.

Pausing and resuming processes

  1. Run the sleep command in the background by appending & at the end of the command

    ./robot-driver.py 10 &
  2. Get the PID of the robot-driver.py program

    jobs -l

    You will notice that the PID of the running program is listed against its name. Note it down.

  3. Pause the command by sending it the SIGSTOP signal

    kill -STOP <pid>
  4. Resume the sleep command by sending it the SIGCONT signal

    kill -CONT <pid>