Understanding Linux Processes, Signals, and Commands
Understanding Linux Processes
A program is a set of instructions and data stored in a file. When loaded into memory to run, it becomes a process. The operating system assigns resources (memory, processor, I/O) to each process for execution.
Every process has a unique identifying number assigned by the kernel, called the Process ID (PID). Processes also have a Parent PID (PPID) identifying the parent process, and a Group ID for related processes.
Process States
Running: On single-processor machines, only one process can be in this state at a time. Linux allows CPU sharing among processes by dividing processor time into slices.
- Sleeping: A process enters this state when waiting for resources or I/O operations.
- Ready to Run: The process is prepared to execute when the CPU scheduler directs.
Linux defines additional process states:
- D: Uninterruptible
- S: Sleeping
- R: Running
- T: Stopped
- X: Dead
- Z: Zombie (in the process of death)
Key Process Commands
ps
Displays information about currently running processes. Without arguments, it shows processes associated with the current terminal.
Syntax: ps [arguments]
Example: ps -ax
Fields in the process list:
- UID: User ID
- PID: Process ID
- PPID: Parent Process ID
- C: CPU resource usage
- STIME: Process start time
- TTY: Associated terminal
- TIME: Allocated CPU time
- COMMAND: Program/process name
- PRI: Process priority
- NI: Nice value (higher values mean lower priority)
- VSZ: Virtual memory image size
- RSS: Resident set size (memory usage)
- STAT: Process state
kill
Sends signals to processes identified by their PID.
Syntax: kill [-signal] PID [PID ...]
Common Signals:
1 (SIGHUP):
Hangup (sent when a terminal disconnects)2 (SIGINT):
Interrupt (sent when Ctrl+C is pressed)3 (SIGQUIT):
Quit (similar to SIGINT, but sent with Ctrl-\)9 (SIGKILL):
Kill (forces process termination)15 (SIGTERM):
Terminate (requests process termination)
nice
Runs a program with a different priority. Regular users can only decrease priority (nice values 1-19, default 10). Administrators can increase priority (negative nice values).
Syntax: nice [-n] command
nohup
Runs a command that continues even after logging out. Output is redirected to nohup.out
or a specified file.
Syntax: nohup command &
sleep
Pauses for a specified number of seconds.
Syntax: sleep seconds
time
Measures the execution time of a command.
Syntax: time command [arguments]
w
Displays information about currently logged-in users and their processes.
fg
Brings a background process to the foreground.
top
Displays real-time information about system processes.
free
Displays memory usage information.
uptime
Shows how long the system has been running.