Skip to content

Linux

Process Management in Linux

Introduction

In Linux, a process is simply a program that is currently running. When you execute a command, it starts a process.

  1. Processes can be categorized into Foreground Processes, which require user input and run in the foreground.
  2. Background processes, which run independently of the user.

Understanding processes is essential for managing and interacting with programs effectively in Linux.


Process States

A process state refers to the current condition or status of a process in its execution lifecycle

graph TD;
    A[Created] --> B[Running]
    B --> C[Sleeping]
    C --> D[Interruptible sleep]
    C --> E[Uninterruptible sleep]
    B --> F[Stopped]
    F --> G[Zombie]

Describing various attributes of a process:

Attribute Description
PID Unique Process ID given to each process.
User Username of the process owner.
PR Priority given to a process while scheduling.
NI 'nice' value of a process.
VIRT Amount of virtual memory used by a process.
RES Amount of physical memory used by a process.
SHR Amount of memory shared with other processes.
S State of the process: 'D' = uninterruptible sleep, 'R' = running, 'S' = sleeping, 'T' = traced or stopped, 'Z' = zombie.
%CPU Percentage of CPU used by the process.
%MEM Percentage of RAM used by the process.
TIME+ Total CPU time consumed by the process.
Command Command used to activate the process.

Useful CLI Shortcuts

General Navigation

  • Ctrl + A: Move to the beginning of the line. Quickly jumps to the start of the current command line.
  • Ctrl + E: Move to the end of the line. Takes you to the end of the current command line for easy editing.

Editing Commands

  • Ctrl + K: Cut the text from the current cursor position to the end of the line. Useful for quickly removing the latter part of a command.
  • Ctrl + U: Cut the text from the current cursor position to the beginning of the line. Clears the command line up to the current cursor position.

Handling Words

  • Alt + B: Move back one word. Navigates backward through the command line, one word at a time.
  • Alt + F: Move forward one word. Moves the cursor forward by one word, making it easier to navigate longer commands.
  • Ctrl + W: Cut the word before the cursor. Removes the word immediately before the cursor, a quick way to delete a single word.
  • Alt + D: Cut the word after the cursor. Deletes the word immediately after the cursor, useful for quick edits.

Command History

  • Ctrl + R: Search the command history. Allows you to search through previously used commands.
  • Ctrl + G: Exit from the history searching mode. Useful for returning to the normal command line mode.

Process Control

  • Ctrl + C: Kill the current process. Stops the currently running command immediately.
  • Ctrl + Z: Suspend the current process. Pauses the running command, allowing you to resume it later.

Miscellaneous

  • Ctrl + L: Clear the screen. Cleans the terminal window for a fresh start.
  • Tab: Auto-complete files, folders, and command names. Saves time by completing commands and paths automatically.

Note: These shortcuts are commonly used in Unix-like systems and may vary slightly based on the terminal or shell you are using.