The Academy

Loading the search index…

Searches the academy on this device only.

Processes, services, packages and logs

Learn how Linux runs programs as processes, how background services are managed, where software comes from and how to read the logs that explain what went wrong.

30 minelementaryUbuntu/LinuxPractical task needs a laptop or desktop

Marking a lesson as read does not prove you can do it. Skills count as demonstrated when you pass the quiz (not yet) and complete the practical tasks (not yet).

By the end of this lesson you will be able to

  • Explain the difference between a program, a process and a service.
  • List your processes with `ps`, find a process ID and stop a harmless practice process with `kill`.
  • Check whether a service is running with `systemctl status` without changing it.
  • Explain how packages, repositories and `apt` fit together.
  • Read recent messages with `journalctl` and know where files in `/var/log` fit.

When something on your laptop is slow, frozen or silently not working, the answers are usually in three places: the list of running programs, the list of background services and the logs, which are the computer's written diary. Learning to look at these without breaking anything is the first step towards fixing problems yourself instead of guessing. This lesson shows you each one, using only safe, read-only commands apart from one tiny practice process that you start yourself.

Program, process and service

A program is a file on your Storage holding instructions, such as the text editor or the web Browser. It does nothing while it sits there. When you start it, the operating system loads it into memory, gives it a share of the CPU and begins following the instructions. That running copy is a Process. If you open the browser twice, you have one program but two or more processes.

Think of a recipe book and a kitchen. The recipe is the program. Each time somebody cooks from it, that is a process. Two people cooking the same recipe at the same moment are two processes of one program.

Linux gives every process a number called the process ID, or PID. Numbers are handed out in order, so a newly started process has a higher number than older ones. The PID is how you point at one particular process when you need to talk about it.

A Service is a process that starts by itself, usually when the computer boots, and keeps running in the background without a window. It waits to do a job for you or for other programs. Examples are the service that manages Wi-Fi and the one that runs scheduled jobs. Linux uses a manager called systemd to start, stop and watch services.

Diagram

A program is a file, a process is that program running, and a service is a process that runs in the background by itself.

Programa file
  • Instructions kept on disk
  • Does nothing until started
  • Example: the text editor
Processprogram running
  • Has its own number (PID)
  • Uses CPU and memory
  • Example: the editor window open now
Servicebackground process
  • Starts by itself at boot
  • No window; waits for work
  • Managed by systemd

Example: cron, the scheduled-jobs service

A program is a file, a process is that program running, and a service is a process that runs in the background by itself.
Read this figure as text

Three columns comparing a program, a process and a service with an example for each.

Three columns. Program: a file of instructions that sits on the disk and does nothing until started; example, the text editor installed on your laptop. Process: a program that is running, with its own process ID (PID); example, the text editor window you have open right now. Service: a process that starts at boot and keeps running in the background, managed by systemd; example, the cron service that runs scheduled jobs.

Looking at processes, and stopping one safely

The command ps (process status) lists processes. On its own it shows only the ones started from your current terminal window. It prints four columns: PID, the terminal it belongs to (TTY), the total CPU time it has used (TIME) and the command name (CMD). The option ps aux shows every process on the computer, which is a very long list. Another command, top, shows the busiest processes and refreshes every few seconds. Press q to leave it.

To practise stopping a process without any risk, you will start one of your own. The command sleep 300 does nothing for 300 seconds. Adding & at the end tells the shell to run it in the background so that you get your prompt back at once. The shell prints a job number and the PID. Then kill followed by the PID asks that process to finish politely.

Start, find and stop a practice process

  1. Step 1: Open the Terminal

    Press Ctrl+Alt+T.

    You should see: A window with a prompt such as amina@laptop:~$ appears.

  2. Step 2: Start a background sleep

    Type sleep 300 & and press Enter.

    You should see: A line such as [1] 2415 appears, and your prompt comes back. The second number is the PID; yours will differ.

  3. Step 3: List your processes

    Type ps.

    You should see: A small table with bash, sleep and ps in the CMD column, each with a PID.

  4. Step 4: Stop the sleep process

    Type kill then a space and the PID of the sleep line, for example kill 2415. Check the number against your own ps output first.

    You should see: No output at first. Press Enter once more and you may see [1]+ Terminated sleep 300.

  5. Step 5: Check that it has gone

    Type ps again.

    You should see: The sleep line is no longer listed.

Simulated interface: not a real screenshot

A simulated terminal that starts a practice process, finds its PID and stops it.

Simulated terminal
  1. Marker 1: Start a harmless process in the background
  2. Marker 2: ps lists it with its PID
  3. Marker 3: kill asks that PID to finish
  4. Marker 4: It is gone from the list
A simulated terminal that starts a practice process, finds its PID and stops it.
Read this figure as text

A simulated terminal showing sleep 300 started in the background, ps listing it, kill stopping it and ps showing it gone.

Simulated terminal, not a real one. Marker 1: the learner types sleep 300 & and the shell prints [1] 2415, the job number and the PID. Marker 2: ps prints a table with columns PID, TTY, TIME and CMD, listing bash with PID 2301, sleep with PID 2415 and ps with PID 2431. Marker 3: kill 2415 stops the sleep process. Marker 4: the next ps lists only bash and ps, so sleep has gone. The numbers are examples.

Services and systemd

To see the state of one service, use systemctl status followed by its name. The word systemctl means 'system control'. The status option only reports; it changes nothing and needs no password. We will look at cron, the service that runs jobs at set times, because Ubuntu installs it by default. The report begins with a coloured dot, then shows whether the service is loaded (its definition was found), enabled (starts at boot), and active (running) or not.

Terminal (Linux) · you can run this on your own computer
systemctl status cron
Report on the cron service. Press q if the output stops and waits.
Simulated interface: not a real screenshot

A simulated terminal showing what systemctl status cron looks like for a healthy service.

Simulated terminal
  1. Marker 1: Ask for the status of one service
  2. Marker 2: enabled: it starts every time the computer boots
  3. Marker 3: active (running): it is working now
  4. Marker 4: Its process ID
A simulated terminal showing what systemctl status cron looks like for a healthy service.
Read this figure as text

A simulated terminal with systemctl status cron output marking the loaded, enabled and active lines.

Simulated terminal, not a real one. The learner types systemctl status cron (marker 1). The first output line is a green dot followed by cron.service - Regular background program processing daemon. The Loaded line says loaded, with the path of its definition file and enabled, meaning it starts at boot (marker 2). The Active line says active (running) since a date, with how long ago (marker 3). The Main PID line says 812 (cron), the process ID of the service (marker 4). Values are examples.

Other commands change services: sudo systemctl stop, start and restart. They need administrator rights and can interrupt networking, printing or even your login. Do not run them while learning unless a lesson or a person you trust explains exactly why. If you ask for a service that is not installed, such as systemctl status ssh on a fresh laptop, you will see Unit ssh.service could not be found. That is not a fault; the service simply is not there.

Packages and repositories

On Linux you rarely download an installer from a random website. Software comes as a Package: a single file holding a program, its settings and a list of what else it needs. Packages are kept in a Repository, an online library run by Ubuntu or another trusted source. The Package manager for Ubuntu is apt. It asks the repository what is available, downloads the package, checks that it has not been tampered with, and installs it along with anything it depends on.

Diagram

How a package travels from the Ubuntu repository to your laptop through apt.

  1. Step 1: RepositoryOnline library
  2. Step 2: apt downloadsChecks it is genuine
  3. Step 3: InstallNeeds admin rights
  4. Step 4: Ready to useUpdate or remove later
How a package travels from the Ubuntu repository to your laptop through apt.
Read this figure as text

A flow of four steps: repository, apt downloads and checks, install, program ready to run.

Four steps in order. One: the repository, an online library of packages run by Ubuntu. Two: apt looks up the package and its dependencies, downloads them and checks that they are genuine. Three: the packages are installed, which needs administrator rights. Four: the program is ready to use and can be updated or removed later in the same way.

You can look without installing anything. apt show nano prints details of the text editor package: version, size, what it needs and a description. apt search followed by a word lists packages whose names or descriptions contain that word. Neither needs sudo. Installing and removing do: for example sudo apt install package-name. Only install packages you understand, from Ubuntu's own repositories. If you add an extra repository from a website, you are trusting that website with your computer.

Logs: the computer's diary

A log is a record of events with a time on each line: a service starting, a Wi-Fi network connecting, a program crashing. When something fails, the log often says why. On modern Ubuntu, most messages are collected by systemd's journal, and you read them with journalctl. The plain-text files in the folder /var/log hold other logs, for example about package installs and the system.

Useful safe examples: journalctl -n 20 prints the last 20 messages. journalctl -p err -b shows only error-level messages (-p err) since the computer last started (-b means this boot). journalctl -u cron -n 5 shows the last 5 messages for the cron service (-u means unit). Long output opens in a viewer: use the arrow keys or space to move and q to leave. Add --no-pager to print straight to the window instead. To see which log files exist, type ls /var/log.

Simulated interface: not a real screenshot

A simulated terminal showing the last messages for the cron service from journalctl.

Simulated terminal
  1. Marker 1: -u cron: only this service; -n 3: last three lines
  2. Marker 2: Time stamp and computer name
  3. Marker 3: Program name and its PID
  4. Marker 4: The message itself
A simulated terminal showing the last messages for the cron service from journalctl.
Read this figure as text

A simulated terminal with journalctl -u cron -n 3 output showing three time-stamped log lines.

Simulated terminal, not a real one. Marker 1: the learner types journalctl -u cron -n 3 --no-pager, meaning the last three messages for the cron service. Each output line has a time stamp (marker 2), the computer name laptop, the program name and its process ID in square brackets (marker 3), then the message (marker 4). The messages say that the cron service started, that it read its job list, and that a job for the user amina ran. Values are examples.

Common mistakes

  • ✖ Instead of: Running kill with a PID copied from an old screenshot or a guess.

    ✔ Do this: Run ps again and use the current PID of the process you started. PIDs change every time.

  • ✖ Instead of: Stopping or restarting services with sudo to see what happens.

    ✔ Do this: Use systemctl status to look. Change a service only when you know what it does and have a reason.

  • ✖ Instead of: Ignoring logs and searching only for the vague symptom.

    ✔ Do this: Read the newest lines in journalctl, copy the exact error message and search for that.

If something goes wrong

kill: (2415) - No such process
That process has already finished, or the number is wrong. Run ps again to see the current PIDs.
systemctl status shows Unit ... could not be found.
The service is not installed or is spelt differently. Check the spelling. Many services, such as ssh, are absent on a standard laptop.
The output stops with a : or lines 1-20 at the bottom and the prompt does not come back.
You are inside a viewer called less. Press q to leave. Next time add --no-pager to print straight to the window.
journalctl says you are not seeing all messages or shows nothing for another user.
Your account may not be in the adm or systemd-journal group. Use id to see your groups. Do not change groups just to read logs; your own messages are usually enough for learning.

Key terms

Process ID
The number, also called a PID, that identifies one running process.
Service
A program that runs in the background, often from start-up, to provide something such as printing or web pages.
systemd
The part of most modern Linux systems, including Ubuntu, that starts services and keeps track of them.
Package
A bundle of software files, with instructions for installing them, that a package manager can add or remove.
Log file
A record that a system or program writes, line by line, about what happened and when.

Practise it for real

Reading is not the same as being able to do it. Complete these on your own computer, then tick only what you have actually done. These ticks are your own honest record: nothing checks them for you.

Guided exerciseNeeds a laptop or desktop

A tour of processes, services and logs

On your laptop, open the Terminal. Start sleep 300 &, note its PID with ps, then stop it with kill and the PID, and check with ps that it has gone. Then run systemctl status cron and write down whether it is enabled and active. Finally run journalctl -n 10 --no-pager and write down the time stamp of the newest line and the name of the program that wrote it.

You have succeeded when:
Independent challenge

Challenge: investigate a slow laptop on paper

A friend says her laptop became slow after lunch. Write a plan of five safe steps you would take using the commands from this lesson, in order. For each step say what you would look for and what you would deliberately not do. Include at least one step that uses top, one that uses a log and one sentence explaining why you would not use kill -9 at once.

You have succeeded when:

Knowledge check

7 questions. You need 80% to pass. Mistakes here are part of learning, and you can retry as often as you like.

  1. Question 1.What is a process?
  2. Question 2.Match each command to what it does.
  3. Question 3.If your laptop is slow, the best first step is to run sudo kill -9 on any process that looks unfamiliar.
  4. Question 4.You type systemctl status cron and see Loaded: loaded (...; enabled; ...) and Active: active (running) since ....What does this tell you?
  5. Question 5.Put these steps of installing software with apt in the correct order.
    1. apt downloads and checks it
    2. The package is installed with administrator rights
    3. The program is ready to use
    4. The repository lists the package
  6. Question 6.A website tells you to run curl https://example.com/setup | sudo bash. What is the main danger?
  7. Question 7.Which command shows only error messages since the computer last started?

Summary

  • A program is a file, a process is a running program and a service is a background process managed by systemd.
  • `ps` lists processes and their PIDs; `kill PID` asks one to stop. Only stop processes you started.
  • `systemctl status name` shows if a service is loaded, enabled and active without changing it.
  • Packages come from trusted repositories through `apt`. Never pipe a download into a shell.
  • `journalctl` and `/var/log` hold the computer's written history; start with the newest lines.

Checklist: can you do these?

Marking a lesson as read does not prove you can do it. Skills count as demonstrated when you pass the quiz (not yet) and complete the practical tasks (not yet).

Related lessons

References and further reading

Official sources for details that can change between versions.

On this page