🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Web & Software Development › Linux/Bash for Web & Software Development › Lesson 8
TEC-WEB46-06 · Lesson 8 · 12 clock hours · lab

System Services and Process Management

Objective. Students will manage Linux services with systemctl, monitor and control processes with ps, top, kill, and nice, and configure a simple custom systemd unit file.

⚠ Pending professional review

This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.

VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.

System Services and Process Management

What Is a Linux Service?

A service (also called a daemon) is a background program that starts automatically and waits to respond to requests — a web server, a database engine, or a logging agent, for example. On modern Linux distributions, the systemd init system manages these services. It is the first process launched by the kernel (PID 1) and is responsible for bringing the rest of the system up in the correct order.

Managing Services with systemctl

`systemctl` is the command-line tool that communicates with systemd. The most common operations are:

| Action | Command |

|---|---|

| Start a service right now | `sudo systemctl start apache2` |

| Stop a running service | `sudo systemctl stop apache2` |

| Restart a service | `sudo systemctl restart apache2` |

| Check current status | `sudo systemctl status apache2` |

| Enable at boot | `sudo systemctl enable apache2` |

| Disable at boot | `sudo systemctl disable apache2` |

Start vs. Enable — a critical distinction. `start` affects the current session only; the service stops when the machine reboots. `enable` creates a symbolic link so systemd starts the service automatically on every future boot, but it does not start the service right now. In practice you often run both: `sudo systemctl enable --now apache2` starts the service and enables it in a single step.

Monitoring Processes

Every running program is a process with a unique PID (Process ID). Two essential tools for watching processes are:

Controlling Priority with nice and renice

Linux schedules CPU time partly based on a process's nice value, which ranges from -20 (highest priority, least nice to other processes) to +19 (lowest priority, most yielding). The default nice value is 0.

Only the root user (or a user with appropriate privileges via `sudo`) can lower a nice value (increase priority). Any user can raise their own process's nice value.

Stopping Processes with kill

`kill` sends a signal to a process. Common signals:

Syntax: `kill -15 <PID>` or `kill -SIGTERM <PID>`. After sending SIGTERM, wait a few seconds, then run `ps aux | grep <PID>` to confirm the process is gone before escalating to SIGKILL.

Writing a Custom systemd Unit File

A unit file is a plain-text configuration file that tells systemd how to manage a service. Unit files for custom services live in `/etc/systemd/system/`. A minimal service unit file has three sections:

```ini

[Unit]

Description=Deploy Check Service

After=network.target

[Service]

Type=oneshot

ExecStart=/usr/local/bin/deploy_check.sh

RemainAfterExit=yes

[Install]

WantedBy=multi-user.target

```

After placing the file (e.g., `/etc/systemd/system/deploy-check.service`), always run `sudo systemctl daemon-reload` to make systemd read the new file before enabling or starting it.

Safety and Best Practices

Key terms10

systemdThe init system used by most modern Linux distributions; it is the first user-space process (PID 1) and manages all other services and their startup order.
systemctlThe command-line utility used to interact with systemd — starting, stopping, enabling, disabling, and inspecting services and units.
unit fileA plain-text INI-style configuration file that describes a systemd-managed resource (service, socket, timer, etc.) and how it should be started and ordered.
daemon-reloadThe systemctl subcommand (`systemctl daemon-reload`) that instructs systemd to re-read all unit files from disk after a new or changed file is placed in the unit directories.
nice valueA number from -20 (highest CPU scheduling priority) to +19 (lowest) that influences how much CPU time the scheduler grants a process relative to others.
SIGTERMSignal number 15; a graceful termination request that allows a process to clean up resources before exiting. It is the preferred first signal to send when stopping a process.
SIGKILLSignal number 9; an immediate, forced termination that cannot be caught or ignored by the process. Used only when SIGTERM fails to stop a process.
PIDProcess ID — a unique integer the kernel assigns to every running process, used to target processes with commands such as kill and renice.
enable (systemctl)A systemctl action that creates a symbolic link so a service starts automatically on future boots; it does not start the service in the current session.
multi-user.targetThe systemd target that represents a fully operational multi-user, non-graphical system state; the standard boot target for servers and most headless Linux systems.
In class: Lab exercise: students start, stop, enable, disable, and check the status of Apache2 using systemctl; they record the difference between 'start' and 'enable' in their lab logs with a concrete example. · Process control drill: instructor launches a CPU-intensive background process with a low nice value; students identify it using top, renice it to a higher value, and finally kill it gracefully with SIGTERM then confirm it is gone. · Custom unit file: students create a systemd service unit file that runs their deploy_check.sh script on boot, place it in /etc/systemd/system/, reload the daemon, enable the service, and verify it appears in 'systemctl list-units'.
Materials: Student VMs, systemd man pages (systemctl, systemd.service), lab instruction sheet
Check: Instructor verifies that the custom unit file loads without errors (systemctl status shows 'loaded'), the service is enabled, and the process control drill steps are documented correctly in the lab log — pass requires all three items confirmed.

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

Linux fundamentals — system services
1. A web server is running on a Linux VM. A student runs `sudo systemctl stop apache2`. What is the most likely behavior after the VM is rebooted?
Linux fundamentals — system administration
2. Which directory is the correct location for a custom systemd service unit file written by a system administrator?
Linux fundamentals — system services
3. After placing a new unit file in /etc/systemd/system/, which command must be run before enabling the service?
Linux fundamentals — process management
4. A student sees a process consuming 95% CPU in `top`. They want to reduce its scheduling priority without stopping it. Which command achieves this, assuming the process PID is 4821?
Linux fundamentals — process management
5. What is the correct sequence for gracefully stopping a runaway process with PID 7734?
Linux fundamentals — system services
6. In a systemd unit file, which section contains the `WantedBy=multi-user.target` directive?
Linux fundamentals — system services
7. A student runs `ps aux | grep deploy_check` immediately after boot and sees the process listed. They then run `systemctl status deploy-check.service` and see 'loaded' but 'inactive (dead)'. What is the most likely explanation?
ITF+ — IT concepts and terminology (operating systems)
8. Which CompTIA ITF+ concept is most directly demonstrated when a student observes that a Linux process with a nice value of -10 receives more CPU time than a process with a nice value of +10?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.