2.6. Working with Processes
Table of Contents
Introduction
Processes are the running programs on your Linux system. Any time you open a web browser, run a command in the terminal, or start a background service, Linux creates one or more processes. Understanding processes is essential for diagnosing slow systems, stopping misbehaving programs, and managing what is running on your machine.
This chapter introduces the general ideas that apply to processes in Linux. The specific commands for viewing processes, killing them, working with foreground and background jobs, and managing system services are covered in their own sections later in this part of the course. Here, you will learn what a process is, how Linux identifies processes, and what kinds of information and states a process can have.
What Is a Process in Linux?
A process is an instance of a program that is currently executing. The program itself is just data stored on disk in an executable file. When you run the program, the kernel loads it into memory, sets up the resources it needs, and turns it into a process.
Every process has its own memory space, certain permissions, and a set of resources such as open files or network connections. The kernel keeps track of all processes and decides when each one is allowed to use the CPU.
Some typical examples of processes include your terminal emulator, the shell that runs inside the terminal, your file manager, a web browser, or a web server on a remote machine. Even many small commands such as ls or cat are processes while they run.
Important: A program is a file stored on disk. A process is a running instance of a program that the kernel manages in memory.
Process Identification and the PID
Linux identifies every process with a Process ID, shortened to PID. The PID is a number that is unique among all currently running processes. When a process exits, its PID can later be reused by another process, but at any moment two processes on the same system cannot share the same PID.
The kernel starts a process, assigns it a PID, and then stores information about it in internal tables. Many tools you will learn later use the PID to refer to and control processes. For example, when you terminate a process manually, you usually refer to it by PID.
You can think of the PID as a label that lets the kernel and userspace tools talk about a specific running instance. When the process ends, that label no longer points to anything.
Parent and Child Processes
In Linux, almost every process is created by another process. The existing process calls into the kernel to create a new process, which becomes its child. The original process is then known as the parent. This creates a tree of processes that ultimately traces back to an initial process that the kernel starts during boot.
When you run a command in a shell, the shell starts a new process for that command and becomes its parent. For instance, if you run ls, your shell process will call the kernel to start a child process that runs the ls program. When ls finishes, the child process exits and the shell can accept a new command.
Each process knows the PID of its parent, which is called the PPID. Tools for viewing processes show both PID and PPID. This parent child relationship is important for understanding how processes are organized and how they can be managed as groups.
Process States
A process is not always using the CPU. Sometimes it is actively running, sometimes it is paused waiting for input, and sometimes it has finished but is not yet completely cleaned up. Linux uses process states to describe what a process is doing at any time.
The most common high level states include running, sleeping, stopped, and zombie. A running process is either currently executing on a CPU or is ready to execute as soon as the scheduler selects it. A sleeping process is waiting for some event such as input from the user, data from disk, or a network reply. A stopped process has been paused, often by a signal.
A zombie process is a special case. It is a process that has finished executing but whose parent has not yet collected its exit status. The kernel keeps a minimal record of it so the parent can read how it exited. Zombies do not consume CPU or real memory, but a large number of them can indicate that some parent process is not behaving correctly.
Process viewers show these states with short codes. You will see how to read those codes when working with the tools that display processes.
How Linux Schedules Processes
Your system usually has far more processes than CPU cores. Linux uses a scheduler inside the kernel to share CPU time among them. The scheduler quickly switches between processes so that it appears as if many processes are running at the same time, even on a single core.
Each process has a priority that influences how often and how long it is allowed to run. There are different scheduling classes, such as normal and real time, and within these classes the priority affects scheduling decisions. For most desktop and server use, Linux handles scheduling automatically and you do not need to change priorities.
The scheduler aims to keep interactive applications responsive while still allowing background tasks to make progress. When the kernel decides a process should be paused, it saves its state and later restores it when the process is scheduled again. From the point of view of the process, it continues as if nothing happened.
Users, Permissions, and Processes
Every process runs as some user, often with specific group memberships. The user ID and group ID associated with a process determine what files it can open, what network ports it can bind to, and what operations are allowed. For example, normal user processes generally cannot modify system files that belong to the root user.
When you start a program from your shell, the process inherits your user identity and your environment. This includes environment variables and the current working directory. Some programs can temporarily change their active identity if they have special permissions, but the basic idea remains that permissions protect the system from untrusted or buggy programs.
System services and daemons that need broad access often run as dedicated service users or as root. To perform administrative actions from a shell, you typically run commands with elevated privileges, which starts new processes with more powerful permissions. The specifics of how to do this safely are covered where sudo and system services are discussed.
Process Resources
The kernel tracks the resources that each process uses. These resources include CPU time, memory, open files, network connections, and more. Each process has its own virtual memory space so that programs cannot directly read or write the memory of others. This separation increases stability and security.
Linux also supports limits on process resources. For example, there can be a maximum number of files a process is allowed to open or a ceiling on how much memory it can allocate. These limits help prevent a single runaway process from consuming all resources and causing the system to become unresponsive.
From the user perspective, you will observe resource usage through monitoring tools that show CPU percentage, memory usage, and other metrics for each process. In later chapters on system monitoring, you will learn how to interpret those metrics in more detail.
Environment and Inheritance
When a new process is created, it inherits several properties from its parent process. One important property is the environment, which consists of environment variables that store configuration values in key value format. Another property is the current working directory, which is the directory where relative paths are resolved.
This inheritance means that the context from your shell carries over into programs you start. If you change an environment variable in your shell, then run a command, the new process sees that updated environment variable. Changes made inside the child process do not flow back into the parent process.
Processes also inherit file descriptors from their parents. For terminal commands, this usually means standard input, standard output, and standard error. Later, when you learn about input and output redirection, you will see how these inherited descriptors are used to connect processes together in pipelines.
Signals and Process Control
Linux uses signals as a basic mechanism to communicate with processes. A signal is a small notification sent to a process that tells it something happened, such as a request to terminate or an instruction to stop temporarily. The process can react to a signal by exiting, cleaning up, or ignoring it, depending on the signal type and how the program is written.
For interactive use, the most visible signals are those triggered by keyboard shortcuts in the terminal. For example, a specific key combination usually sends an interrupt signal that asks the foreground process to stop. Another combination stops the process but keeps it in memory so that it can be resumed.
There are also signals that tell a process to reload its configuration, to pause, or to terminate immediately. Tools for killing processes send these signals systemwide, not just from the terminal. The detailed use of these tools and signal types will be covered where process control commands are explained.
Foreground, Background, and Daemons
Processes that run in a terminal can be in the foreground or in the background. A foreground process is directly attached to the terminal, and it receives keyboard input and prints output there. While a long running command occupies the foreground, your shell waits for it to finish before accepting new input.
Background processes are still running, but they are not actively using the terminal for input. Starting or moving a process into the background lets you keep working in the same terminal. Job control features in shells help you manage this, and their use is discussed in the chapter on foreground and background jobs.
Daemons are long running background processes that do not usually have a terminal at all. They often start during boot and provide services such as web serving, logging, or scheduling tasks. On modern Linux systems, daemons are typically managed by an init system such as systemd, which controls their lifecycle.
System Services and Process Management
On a modern Linux distribution, many important processes are system services. These are daemons managed by a central service manager that starts them, stops them, restarts them if they crash, and keeps track of their status. For example, your networking service, display manager, and logging service are all processes under this system manager.
From the point of view of the kernel, services are still just processes, but they are started and controlled in a structured way. Instead of running them manually from a terminal, you use management commands that talk to the service manager. This makes sure dependencies are handled and that services restart correctly when needed.
Administrative tools for services provide information such as whether a service is active, when it started, and why it stopped. You will learn to use these tools in later chapters about systemd and service management, where you will see how process concepts apply to real system services.
Why Processes Matter to Everyday Use
Even for a beginner, understanding processes improves day to day work on Linux. When an application freezes, knowing that it is just a process lets you find it and stop it safely. If your computer feels slow, you can look at which processes are using the most CPU or memory and decide how to respond.
As you progress, you will interact with processes constantly, whether you are running commands, writing scripts, or managing servers. Every tool that shows system activity is, at its core, showing you information about processes. With the foundation from this chapter, you are ready to learn the specific commands that let you view, control, and manage them in detail.
Views: 0
Where to Move
Move chapter:
- ☰ 1. PART I — Linux Fundamentals (Beginner)
- ☰ 1.1. What Is Linux?
- ☰ 1.1.1. What is an operating system
- ☰ 1.1.2. History of Unix and Linux
- ☰ 1.1.3. The Linux kernel
- ☰ 1.1.4. GNU and the Free Software Foundation
- ☰ 1.1.5. Open source philosophy
- ☰ 1.1.6. Where Linux is used today
- ☰ 1.1.7. Desktop vs server vs embedded Linux
-
- ☰ 1.2. Choosing a Linux Distribution
- ☰ 1.2.1. What is a distribution?
- ☰ 1.2.2. Package formats (deb, rpm, pacman)
- ☰ 1.2.3. Popular distributions
- ☰ 1.2.3.1. Ubuntu
- ☰ 1.2.3.2. Debian
- ☰ 1.2.3.3. Fedora
- ☰ 1.2.3.4. Arch Linux
- ☰ 1.2.3.5. openSUSE
-
- ☰ 1.2.4. Rolling vs fixed release
- ☰ 1.2.5. Choosing the right distribution
-
- ☰ 1.3. Installing Linux
- ☰ 1.3.1. Creating a bootable USB
- ☰ 1.3.2. Installing on real hardware
- ☰ 1.3.3. Dual booting with Windows
- ☰ 1.3.4. Installing in a virtual machine
- ☰ 1.3.5. Partitioning
- ☰ 1.3.5.1. `/` (root)
- ☰ 1.3.5.2. `/home`
- ☰ 1.3.5.3. Swap
-
- ☰ 1.3.6. First-time setup
-
- ☰ 1.4. First Steps After Installation
- ☰ 1.4.1. Desktop environment basics
- ☰ 1.4.2. Updating the system
- ☰ 1.4.3. Installing essential tools
- ☰ 1.4.4. Setting up drivers
- ☰ 1.4.5. Using the software center
-
- ☰ 1.5. Linux Filesystem Hierarchy
- ☰ 1.5.1. Overview of the root filesystem
- ☰ 1.5.2. Important directories
- ☰ 1.5.2.1. `/etc`
- ☰ 1.5.2.2. `/var`
- ☰ 1.5.2.3. `/usr`
- ☰ 1.5.2.4. `/tmp`
- ☰ 1.5.2.5. `/dev`
- ☰ 1.5.2.6. `/proc`
- ☰ 1.5.2.7. `/sys`
-
- ☰ 1.5.3. File types
- ☰ 1.5.4. Absolute vs relative paths
-
- ☰ 1.6. The Linux Graphical Environment
- ☰ 1.6.1. GNOME
- ☰ 1.6.2. KDE Plasma
- ☰ 1.6.3. XFCE
- ☰ 1.6.4. File managers
- ☰ 1.6.5. System settings
- ☰ 1.6.6. Workspaces and window management
-
-
- ☰ 2. PART II — Command Line Essentials
- ☰ 2.1. Terminal and Shell Basics
- ☰ 2.1.1. What is a shell?
- ☰ 2.1.2. Bash vs Zsh vs Fish
- ☰ 2.1.3. Command structure
- ☰ 2.1.4. Environment variables
- ☰ 2.1.5. Getting help
- ☰ 2.1.6. Command history and autocomplete
-
- ☰ 2.2. Files and Directories
- ☰ 2.2.1. Listing files
- ☰ 2.2.2. Navigating directories
- ☰ 2.2.3. File operations
- ☰ 2.2.4. Wildcards and globbing
- ☰ 2.2.5. Searching files
-
- ☰ 2.3. Viewing and Editing Text Files
- ☰ 2.3.1. Viewing tools
- ☰ 2.3.2. Editing with nano
- ☰ 2.3.3. Introduction to vim
- ☰ 2.3.4. Input/output redirection
-
- ☰ 2.4. Users, Permissions, and Ownership
- ☰ 2.4.1. Users and groups
- ☰ 2.4.2. Permission types (r, w, x)
- ☰ 2.4.3. Changing permissions
- ☰ 2.4.4. Changing ownership
- ☰ 2.4.5. Using sudo
-
- ☰ 2.5. Package Management
- ☰ 2.5.1. Software repositories
- ☰ 2.5.2. APT (Debian/Ubuntu)
- ☰ 2.5.3. DNF (Fedora/RHEL)
- ☰ 2.5.4. Pacman (Arch Linux)
- ☰ 2.5.5. Snap, Flatpak, AppImage
- ☰ 2.5.6. System upgrades
-
- ☰ 2.6. Working with Processes
- ☰ 2.6.1. What is a process?
- ☰ 2.6.2. Viewing processes
- ☰ 2.6.3. Killing processes
- ☰ 2.6.4. Foreground and background jobs
- ☰ 2.6.5. System services and daemons
-
- ☰ 2.7. Introduction to Shell Scripting
- ☰ 2.7.1. Writing your first script
- ☰ 2.7.2. Variables
- ☰ 2.7.3. Conditionals
- ☰ 2.7.4. Loops
- ☰ 2.7.5. Functions
- ☰ 2.7.6. Making scripts executable
-
-
- ☰ 3. PART III — Intermediate System Administration
- ☰ 3.1. Systemd and Service Management
- ☰ 3.1.1. What is systemd?
- ☰ 3.1.2. Managing services (systemctl)
- ☰ 3.1.3. Boot targets
- ☰ 3.1.4. System logs (journalctl)
- ☰ 3.1.5. Creating custom services
-
- ☰ 3.2. Storage and Filesystems
- ☰ 3.2.1. Devices and partitions
- ☰ 3.2.2. Filesystems (EXT4, XFS, Btrfs)
- ☰ 3.2.3. Mounting and unmounting
- ☰ 3.2.4. Disk usage tools
- ☰ 3.2.5. Archiving and compression (tar, gzip, xz)
-
- ☰ 3.3. Networking Fundamentals
- ☰ 3.3.1. IP addressing
- ☰ 3.3.2. Subnets and routing
- ☰ 3.3.3. DNS and hostnames
- ☰ 3.3.4. Networking tools (ip, ss, ping)
- ☰ 3.3.5. Editing network configuration files
-
- ☰ 3.4. User and Group Administration
- ☰ 3.4.1. User information files
- ☰ 3.4.2. Creating and removing users
- ☰ 3.4.3. Password policies
- ☰ 3.4.4. Managing groups
- ☰ 3.4.5. Shell configuration
-
- ☰ 3.5. System Monitoring
- ☰ 3.5.1. CPU and memory monitoring
- ☰ 3.5.2. Disk and I/O monitoring
- ☰ 3.5.3. Log files in /var/log
- ☰ 3.5.4. Boot performance
- ☰ 3.5.5. Monitoring running services
-
- ☰ 3.6. Backup and Restore
- ☰ 3.6.1. Backup strategies
- ☰ 3.6.2. Using rsync
- ☰ 3.6.3. Creating tar archives
- ☰ 3.6.4. Using snapshot systems
- ☰ 3.6.5. Automating backups
-
- ☰ 3.7. Basic System Security
- ☰ 3.7.1. Firewalls (UFW, firewalld)
- ☰ 3.7.2. Authentication policies
- ☰ 3.7.3. SSH security basics
- ☰ 3.7.4. SELinux and AppArmor overview
- ☰ 3.7.5. Intrusion detection basics
-
-
- ☰ 4. PART IV — Advanced Linux Skills
- ☰ 4.1. Advanced Shell Scripting
- ☰ 4.1.1. Script structure
- ☰ 4.1.2. Error handling
- ☰ 4.1.3. Debugging scripts
- ☰ 4.1.4. Scheduled tasks (cron)
-
- ☰ 4.2. The Linux Boot Process
- ☰ 4.2.1. BIOS vs UEFI
- ☰ 4.2.2. Understanding GRUB2
- ☰ 4.2.3. Kernel loading
- ☰ 4.2.4. initramfs
- ☰ 4.2.5. Troubleshooting boot issues
-
- ☰ 4.3. Kernel Management
- ☰ 4.3.1. What is the kernel?
- ☰ 4.3.2. Kernel modules
- ☰ 4.3.3. Kernel parameters
- ☰ 4.3.4. Compiling a custom kernel
- ☰ 4.3.5. Kernel versioning and updates
-
- ☰ 4.4. Advanced Filesystems and Storage
- ☰ 4.4.1. LVM concepts
- ☰ 4.4.2. Logical volumes
- ☰ 4.4.3. RAID levels
- ☰ 4.4.4. Full disk encryption (LUKS)
- ☰ 4.4.5. Snapshots and rollbacks
-
- ☰ 4.5. Network Services
- ☰ 4.5.1. SSH server configuration
- ☰ 4.5.2. NFS
- ☰ 4.5.3. Samba
- ☰ 4.5.4. FTP/SFTP
- ☰ 4.5.5. Firewalls in depth
-
- ☰ 4.6. Logging and Auditing
- ☰ 4.6.1. Systemd logging
- ☰ 4.6.2. Traditional logs in /var/log
- ☰ 4.6.3. Auditd
- ☰ 4.6.4. Log rotation
- ☰ 4.6.5. Creating custom logs
-
- ☰ 4.7. Virtualization and Containers
- ☰ 4.7.1. Virtual machines (KVM/QEMU)
- ☰ 4.7.2. Linux containers (LXC/LXD)
- ☰ 4.7.3. Docker fundamentals
- ☰ 4.7.4. Podman vs Docker
- ☰ 4.7.5. Container networking
-
-
- ☰ 5. PART V — Server Administration (Expert)
- ☰ 5.1. Web Servers
- ☰ 5.1.1. Apache basics
- ☰ 5.1.2. Nginx basics
- ☰ 5.1.3. Virtual hosts
- ☰ 5.1.4. SSL/HTTPS
- ☰ 5.1.5. Reverse proxy concepts
-
- ☰ 5.2. Database Servers
- ☰ 5.2.1. MySQL/MariaDB
- ☰ 5.2.2. PostgreSQL
- ☰ 5.2.3. Database backup strategies
- ☰ 5.2.4. Database hardening
-
- ☰ 5.3. Email Services
- ☰ 5.3.1. SMTP fundamentals
- ☰ 5.3.2. Configuring Postfix
- ☰ 5.3.3. IMAP/POP3 with Dovecot
- ☰ 5.3.4. Spam filtering systems
- ☰ 5.3.5. Email routing concepts
-
- ☰ 5.4. DNS and DHCP
- ☰ 5.4.1. Understanding DNS
- ☰ 5.4.2. Setting up BIND
- ☰ 5.4.3. DNS zones and records
- ☰ 5.4.4. DHCP server configuration
- ☰ 5.4.5. DNS troubleshooting
-
- ☰ 5.5. Load Balancing
- ☰ 5.5.1. HAProxy fundamentals
- ☰ 5.5.2. Nginx as a load balancer
- ☰ 5.5.3. Session persistence
- ☰ 5.5.4. High availability concepts
-
- ☰ 5.6. Clustering and High Availability
- ☰ 5.6.1. Failover principles
- ☰ 5.6.2. Pacemaker
- ☰ 5.6.3. Corosync
- ☰ 5.6.4. Cluster resource management
- ☰ 5.6.5. Distributed filesystems
-
-
- ☰ 6. PART VI — DevOps and Cloud
- ☰ 6.1. Linux for Developers
- ☰ 6.1.1. Compiler toolchains (gcc, make)
- ☰ 6.1.2. Git fundamentals
- ☰ 6.1.3. Debugging tools (gdb, strace)
- ☰ 6.1.4. Build automation (Makefile, CMake)
-
- ☰ 6.2. DevOps on Linux
- ☰ 6.2.1. CI/CD principles
- ☰ 6.2.2. YAML basics
- ☰ 6.2.3. GitHub Actions
- ☰ 6.2.4. GitLab CI/CD
- ☰ 6.2.5. Automated testing
-
- ☰ 6.3. Configuration Management
- ☰ 6.3.1. Ansible basics
- ☰ 6.3.2. Playbooks and inventories
- ☰ 6.3.3. Puppet overview
- ☰ 6.3.4. Chef overview
-
- ☰ 6.4. Infrastructure as Code
- ☰ 6.4.1. Terraform fundamentals
- ☰ 6.4.2. Providers and resources
- ☰ 6.4.3. Modules
- ☰ 6.4.4. Cloud provisioning with Terraform
-
- ☰ 6.5. Cloud Computing with Linux
- ☰ 6.5.1. Linux on AWS
- ☰ 6.5.2. Linux on Azure
- ☰ 6.5.3. Linux on GCP
- ☰ 6.5.4. Cloud networking basics
- ☰ 6.5.5. Scaling and monitoring
-
-
- ☰ 7. PART VII — Master Topics
- ☰ 7.1. Hardening a Linux System
- ☰ 7.1.1. Hardening principles
- ☰ 7.1.2. Kernel hardening
- ☰ 7.1.3. File integrity monitoring
- ☰ 7.1.4. Vulnerability scanning
-
- ☰ 7.2. Forensics and Incident Response
- ☰ 7.2.1. Collecting evidence
- ☰ 7.2.2. Log and file recovery
- ☰ 7.2.3. Analyzing suspicious processes
- ☰ 7.2.4. Incident response workflow
-
- ☰ 7.3. Performance Tuning
- ☰ 7.3.1. CPU tuning
- ☰ 7.3.2. Memory tuning
- ☰ 7.3.3. Disk and I/O optimization
- ☰ 7.3.4. Profiling tools
-
- ☰ 7.4. Writing Linux Tools
- ☰ 7.4.1. Bash-based tools
- ☰ 7.4.2. Python command-line tools
- ☰ 7.4.3. Writing tools in C
- ☰ 7.4.4. Using Linux system APIs
-
- ☰ 7.5. Linux Internals
- ☰ 7.5.1. Process lifecycle
- ☰ 7.5.2. Memory management
- ☰ 7.5.3. Signals and IPC
- ☰ 7.5.4. Namespaces
- ☰ 7.5.5. cgroups
-
- ☰ 7.6. Becoming a Linux Expert
- ☰ 7.6.1. Career paths
- ☰ 7.6.2. Certifications (RHCE, LFCS, LPIC)
- ☰ 7.6.3. Building a homelab
- ☰ 7.6.4. Contributing to open source
-
-
Comments
Please login to add a comment.
Don't have an account? Register now!