Linux Process Basics
What is a Process?
In Linux, a process is an instance of a running program. When you launch an application or execute a command, the system creates a process with a unique Process ID (PID). Each process has its own memory space, system resources, and execution context.
Process States
Processes in Linux can exist in different states:
State |
Description |
Running |
Currently executing on the CPU |
Sleeping |
Waiting for a system resource or event |
Stopped |
Paused and can be resumed |
Zombie |
Completed execution but still in process table |
Process Hierarchy
graph TD
A[systemd - PID 1] --> B[Parent Process]
B --> C[Child Process 1]
B --> D[Child Process 2]
Linux uses a parent-child process model where every process (except systemd) is created by another process. The systemd
process is the root of all processes with PID 1.
Viewing Processes
You can view running processes using several commands:
ps
command:
## List all processes
ps aux
## Show processes for current user
ps -u $(whoami)
top
command:
## Interactive real-time process viewer
top
Process Attributes
Key process attributes include:
- PID (Process ID)
- PPID (Parent Process ID)
- User
- CPU and Memory Usage
- Current State
Process Creation
Processes are created using system calls like fork()
and exec()
. When you run a command, Linux typically:
- Forks a new process
- Executes the specified program
Resource Management
Processes consume system resources:
- CPU time
- Memory
- File descriptors
- Network sockets
At LabEx, we recommend understanding process management for efficient system performance and troubleshooting.