LinuxShellSite
CommandDescriptionSyntax/ExamplePlatform Notes
psDisplays information about running processes.ps auxAll Platforms
topInteractive real-time tool to display process information.topAll Platforms
htopExtended version of top with improved user interface.htopPossibly reinstall
pstreeDisplays processes in a tree-like structure.pstreeAll Platforms
killSends signals to processes, usually to terminate.kill -9 PIDAll Platforms
killallTerminates processes by name.killall nameAll Platforms
pkillTerminates processes based on a pattern matching of their name.pkill -f patternAll Platforms
pgrepSearches for processes based on pattern matching and outputs the PIDs.pgrep -l nameAll Platforms
niceStarts a new process with adjusted priority.nice -n 10 commandAll Platforms
ReniceChanges the priority of a running process.renice -n 5 -p PIDAll Platforms
nohupExecutes a command that does not stop when you log off.nohup command &All Platforms
BGContinues to run a paused process in the background.bg %Job numberAll Platforms
fgBrings a background process to the fore.fg %Job numberAll Platforms
JobsLists current jobs in the shell.JobsAll Platforms
lsofLists open files and associated processes.lsof -p PIDAll Platforms
straceTracks system calls to a troubleshooting process.strace -p PIDAll Platforms
systemctlManagement of systemd services and units.systemctl statusSystems with Systemd (Ubuntu, RHEL 7+, CentOS 7+)
ServiceStarts, stops, or checks services (older command).Service Name StatusSystems with SysVinit (older systems)
initChanges the runlevel of the system or performs a reboot/shutdown.init 0Systems with SysVinit
chrtChanges the scheduling priority of a process.chrt -p 0 PIDAll Platforms
TimeoutExecutes a command for a specified amount of time.Timeout 5s commandAll Platforms
pmapDisplays the memory allocation of a process.pmap PIDAll Platforms
vmstatDisplays system performance and memory usage.VMSTAT 1All Platforms
IOSTATDisplays CPU and I/O statistics.IOSTATAll Platforms
sarSystem Activity Reporter, collects and reports system activity data.sar -u 1 3Possibly reinstall (sysstat package)
pidofReturns the PID of a running process by its name.pidof process-nameAll Platforms
watchPeriodically executes a command and displays the result.watch commandAll Platforms

Platform Notes:

  • All platforms: These commands are available on most Linux distributions.
  • Possibly reinstall: Some commands like htop or sar are not installed by default and need to be added via the package manager.
    • Ubuntu/Debian: Installation with sudo apt install htop.
    • RHEL/CentOS: Install with sudo yum install htop.
  • Systems with Systemd: Newer distributions such as Ubuntu (from 15.04), RHEL/CentOS (from version 7) use Systemd.
  • Systems with SysVinit: Older systems use init scripts and the service command.

Explanations of selected commands:

  • ps: With ps aux, all processes of all users are displayed. Option a for all users, u for detailed format, x for processes without a controlling terminal.
  • Top and HTOP:
    • top: Displays running processes in real time, sorted by CPU utilization.
    • htop: Provides a colorful, interactive interface with mouse support and additional features such as scrolling and sorting.
  • kill, killall, pkill:
    • kill: Terminates a process based on its PID.
    • killall: Kills all processes with a specific name.
    • pkill: Terminates processes based on pattern matching.
  • nice and renice:
    • nice: Starts a process with a changed priority (niceness value from -20 to 19).
    • renice: Changes the priority of a running process.
  • Jobs, BG, FG:
    • jobs: Lists all running or suspended jobs in the current shell.
    • bg: Resumes a paused job in the background.
    • fg: Brings a background job to the foreground.
  • LSOF:
    • Useful for identifying processes accessing specific files or ports.
    • Example: lsof -i :80 shows processes that use port 80.
  • strace:
    • Helps troubleshoot by logging system calls and signals of a process.
    • Can be used to understand why a process crashes or hangs.
  • Systemctl:
    • Central command to manage services under systemd.
    • Examples:
      • systemctl start service-name: Starts a service.
      • systemctl stop service-name: Stops a service.
      • systemctl enable service-name: Enables automatic startup at boot.
      • systemctl disable service-name: Disables automatic startup.
  • Service:
    • Used on older systems or those without systemd.
    • Example: service ssh status checks the status of the SSH service.
  • chrt:
    • Can change the scheduling policy and priority of a process.
    • Example: chrt -f -p 99 PID sets a process to real-time priority.
  • Timeout:
    • Terminates a process after a set amount of time.
    • Useful for preventing processes from running for too long.
  • PMAP:
    • Displays detailed information about a process’s memory usage.
    • Helpful in analyzing memory leaks.
  • VMSTAT and IOSTAT:
    • vmstat: Shows statistics on virtual memory, CPU, and system processes.
    • iostat: Monitors system I/O devices and outputs CPU statistics.
  • SAR:
    • Part of the sysstat package.
    • Collects historical data about system activity.
    • Can be used to analyze performance issues over a longer period of time.

Example of installing missing commands:

  • Ubuntu/Debian:
    • sudo apt update
    • sudo apt install htop sysstat
  • RHEL/CentOS:
    • sudo yum update
    • sudo yum install htop sysstat

Tips:

  • Understand process priorities: Lower niceness scores mean higher priority. By default, processes have a niceness value of 0.
  • Send signals with kill:
    • kill -SIGTERM PID or kill -15 PID: Ends a process in a friendly way.
    • kill -SIGKILL PID or kill -9 PID: Kills a process immediately.
  • Identify suspended processes:
    • A process can be stopped with Ctrl+Z.
    • With jobs you can see the paused process and resume it with bg or fg.