Ubuntu 24.04 Terminal CLI Processes and Services: Difference between revisions

From CompleteNoobs
Jump to navigation Jump to search
Test1 (talk | contribs)
Created page with "== Ubuntu 24.04 Processes and Services == Ubuntu 24.04 introduces updated tools and enhancements for managing processes and services. This guide covers how to monitor, control, and optimize processes and services on your Ubuntu 24.04 system, including practical examples like running applications in the background and managing system services with <code>systemd</code>. == Introduction == Processes and services are fundamental to the operation of any Linux system, inclu..."
 
(No difference)

Latest revision as of 20:37, 19 March 2025

Ubuntu 24.04 Processes and Services

Ubuntu 24.04 introduces updated tools and enhancements for managing processes and services. This guide covers how to monitor, control, and optimize processes and services on your Ubuntu 24.04 system, including practical examples like running applications in the background and managing system services with systemd.

Introduction

Processes and services are fundamental to the operation of any Linux system, including Ubuntu 24.04. A process is an instance of a running program, while a service is a background process that provides system functionality, often starting at boot. This page will guide you through understanding, managing, and troubleshooting processes and services in Ubuntu 24.04, with a focus on tools and features specific to this release.

Understanding Processes in Ubuntu 24.04

Process Basics

In Ubuntu 24.04, each process has a unique Process ID (PID) and exists in one of several states:

  • Running: The process is executing or waiting to execute.
  • Sleeping: The process is waiting for an event (e.g., user input).
  • Stopped: The process is paused, often by user action.
  • Zombie: The process has terminated but remains in the process table.

Processes are hierarchical, with parent processes creating child processes. The root of this hierarchy is the init process (PID 1), managed by systemd in Ubuntu 24.04.

Tools for Process Management

Ubuntu 24.04 provides several tools to monitor and manage processes:

  • ps: Lists processes. Use ps aux for a detailed view.
  • top: Displays real-time process information, sorted by CPU usage.
  • htop: An enhanced version of top with a user-friendly interface. Install it with sudo apt install htop.
  • pgrep: Finds processes by name or other attributes. For example, pgrep -f keepassxc finds processes matching "keepassxc".

Ubuntu 24.04 also includes improvements in process scheduling and resource management, optimizing performance for both desktop and server environments.

Background and Foreground Processes

Processes in Ubuntu 24.04 can run in the foreground or background. Understanding how to manage them is key to efficient multitasking in the terminal.

Foreground Processes

Foreground processes run interactively in the terminal, blocking further commands until they complete or are paused. For example, launching nano to edit a file ties up the terminal until you exit the editor.

Background Processes

Background processes run independently of the terminal, allowing you to continue using it for other tasks. This is ideal for long-running applications like downloads or running a KeePassXC AppImage.

Managing Background and Foreground Processes

  • Starting a Process in the Background: Add an ampersand (&) to the command. For example:
./keepassxc.appimage &

This launches KeePassXC in the background, displaying a job number (e.g., [1]) and PID (e.g., 12345).

  • Moving a Foreground Process to the Background: If a process is already running in the foreground:
    • Pause it with Ctrl + Z (e.g., [1]+ Stopped ./keepassxc.appimage).
    • Resume it in the background with:
bg
  • Checking Background Processes: List all background jobs in the current terminal session:
jobs

Output might look like:

[1]+  Running                 ./keepassxc.appimage &

To see all processes (including those not tied to the terminal), use:

ps aux | grep keepassxc
  • Bringing a Background Process to the Foreground: Use the fg command with the job number:
fg %1

Replace %1 with the job number from the jobs output.

  • Closing a Background Process: To terminate a specific background process:
    • Find its PID:
pgrep -f keepassxc.appimage

This might return 12345.

    • Kill it:
kill 12345

Use kill -9 12345 if it doesn’t close gracefully.

  • Persistent Background Processes: Closing the terminal ends background jobs. To keep them running, use nohup:
nohup ./keepassxc.appimage &

Or run them in a tmux or screen session.

Example: Running KeePassXC in the Background

Let’s run a KeePassXC AppImage in the background, check it, and close it:

  • Start KeePassXC:
./keepassxc.appimage &

Output: [1] 12345. KeePassXC runs, and the terminal is free.

  • Check Background Jobs:
jobs

Output: [1]+ Running ./keepassxc.appimage &.

  • Verify with PID:
pgrep -f keepassxc.appimage

Output: 12345.

  • Close KeePassXC:
kill 12345

Verify it’s gone with jobs (empty output) or ps aux | grep keepassxc.

This approach lets you run KeePassXC without tying up your terminal, check its status, and stop it when needed.

System Services in Ubuntu 24.04

Systemd Overview

Ubuntu 24.04 uses systemd as its default init system, managing system services and boot processes. systemd provides better performance and advanced features compared to older init systems.

Managing Services with systemctl

The systemctl command is used to manage services. Common commands include:

  • Start a service:
sudo systemctl start service_name
  • Stop a service:
sudo systemctl stop service_name
  • Enable a service (start at boot):
sudo systemctl enable service_name
  • Disable a service (don’t start at boot):
sudo systemctl disable service_name
  • Check service status:
systemctl status service_name

Common Services in Ubuntu 24.04

Some essential services include:

  • ssh: Allows secure remote access.
  • apache2: Serves web pages.
  • snapd: Manages Snap packages, a key feature in Ubuntu.

Creating Custom Services

You can create your own services with systemd. For example, to start the IPFS daemon at boot:

  • Create a service file:
sudo nano /etc/systemd/system/ipfs.service
  • Add the following content:
[Unit]
Description=Start IPFS daemon

[Service]
Type=simple
ExecStart=/usr/local/bin/ipfs daemon

[Install]
WantedBy=multi-user.target
  1. Enable and start the service:
sudo systemctl enable ipfs.service
sudo systemctl start ipfs

Monitoring and Troubleshooting

Real-Time Monitoring

Use top or htop to monitor processes in real-time:

  • top: Default tool, press q to quit.
  • htop: More interactive, with color-coding and easier navigation.

Viewing Logs

Use journalctl to access service logs:

  • View logs for a service:
journalctl -u service_name
  • Follow live logs:
journalctl -f

Finding Process Issues

To identify resource-heavy processes:

  • Use top or htop and sort by CPU or memory usage.
  • Alternatively, use ps aux | sort -nk 3 to sort by CPU usage.