LogoLogo
  • Welcome
  • Explorers
    • Aptos Explorer
    • Cosmos Explorer
  • Blockchains
    • Aptos
      • Run a Validator and VFN
        • Operator
        • Node Requirements
        • Deploy Nodes
          • Using Source Code
        • Connect Nodes
          • Connect to a Network
          • Staking Pool Operations
          • Delegation Pool Operations
          • Staking Pool Voter
        • Verify Nodes
          • Node Health
          • Validator Leaderboard
        • Modify Nodes
          • Upgrade Nodes
          • Shutdown Nodes
      • Run a Public Fullnode
        • PFN Requirements
        • Deploy a PFN
          • Deploy a PFN using Source Code
        • Verify a PFN
        • Modify a PFN
          • Customize PFN Networks
          • Generate a PFN Identity
          • Upgrade your PFN
          • Run a PFN from Source Code
      • Bootstrap a Node with historical data
        • Bootstrap from a Backup
        • Bootstrap from a Snapshot
      • Configure a Node
        • State Synchronization
        • Data Pruning
        • Telemetry
        • Locating Node Files
          • Files For Mainnet
          • Files For Testnet
          • Files For Devnet
      • Monitor your Nodes
        • Important Node Metrics
        • Node Health Checker
        • Node Health Checker FAQ
        • Node Inspection Service
      • Building Aptos From Source
      • Aptos Networks
    • Berachain V2
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • gRPC Endpoint
      • Live Peers
      • Forest Staking Peer
      • Performance Optimizer Script
      • Discord & TG Alert System
      • RPC Load Balancer Setup
    • Casper
      • Explorer
    • Haqq
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Mantra
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Ika
    • Story Protocol
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • EVM Endpoint
      • Websocket
      • WSS
      • Discord & TG Alert System
      • RPC Load Balancer
      • Performance Optimizer Script
      • Live Peers
      • Forest Staking Peer
    • Supra
      • Explorer
      • Oracle data
    • Showdown
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Soarchain
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Zenrock
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Zetachain
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Airchains
      • Node Snapshot
      • Explorer
  • Gunzilla - Off The Grid
    • Vision and Foundation
    • Gunzilla Hacker Dashboard
      • Key Features of the Hackers Dashboard
        • Wallet Integration and Testnet Access
        • License System with Rarity Tiers
        • Decoding Stats and Hash Power Tracking
        • Marketplace for Trading Licenses and Assets
        • Scanner Tool for Blockchain Transparency
        • Social Media Integration and Community Engagement
      • Mastering the Hackers Dashboard
      • Benefits of the Hackers Dashboard
    • Gunzilla Token Page
  • Forest Esports Team
    • Forest Hexers
  • Crypto Tools & Analytics
    • Top 10 Crypto Exchanges
      • Binance
      • Coinbase
      • Kraken
      • Bybit
      • OKX
      • KuCoin
      • Bitfinex
      • Gemini
      • Crypto.com
      • Bitstamp
    • Top 10 Wallets
      • Ledger Nano X
      • Trezor Model T
      • Exodus
      • Coinbase Wallet
      • Trust Wallet
      • MetaMask
      • Crypto.com DeFi Wallet
      • ZenGo
      • Atomic Wallet
      • SafePal
  • Top 10 Crypto Data Platforms
    • CoinMarketCap
    • CoinGecko
    • CryptoCompare
    • CoinCodex
    • Live Coin Watch
    • CoinCheckup
    • Messari
    • CoinPaprika
    • Arkham Intelligence
  • DeFi Analytics and Tracking
    • DefiLlama
    • Dune Analytics
    • DeBank
    • Zapper
    • Token Terminal
    • DeepDAO
    • Revert Finance
    • L2BEAT
  • API's
    • What are APIs?
    • How APIs Work
    • Types of APIs
    • Real-World API Use Cases
    • Benefits of Using API's
    • Challenges and Considerations of using API's
  • Node Security
    • Physical Security
    • Network Security
    • System and Software Security
    • Access Control
    • Data Security
    • Monitoring and Logging
    • Backup and Disaster Recovery
    • Best Practices for Validator Nodes
    • Cloud Security
    • Incident Response and Recovery
  • Linux Bash
    • Bash 101
      • Getting Started with Bash
      • Navigating the File System
      • File Management Basics
      • Viewing and Editing Files
      • Managing Permissions
      • Working with Processes
      • Using Pipes and Redirection
      • Bash Scripting Basics
      • Essential Networking Commands
      • Installing Software with Package Managers
    • Advanced Linux for Validator Nodes
      • Advanced Bash Scripting for Node Automation and Maintenance
      • Monitoring and Logging Essentials
      • Networking and Security Best Practices
      • Backup and Disaster Recovery
  • Staking 101
    • Understand What Staking Is and How It Works
    • Choose a Blockchain Network to Stake On
    • Set Up a Compatible Wallet for Staking
    • Purchase or Transfer Funds for Staking
    • Choose a Staking Pool
    • Connect Your Wallet to a Staking Platform
    • Confirm and Stake Your Funds
    • Monitor Staking Rewards and Performance
    • Withdraw or Re-Stake Rewards
  • Optimizing Your Infrastructure Choices
    • Infrastructure Comparison: VPS vs. Bare Metal
Powered by GitBook
On this page

Was this helpful?

  1. Linux Bash
  2. Bash 101

Working with Processes

Managing processes in Linux is an essential skill, as it allows you to monitor, control, and terminate running programs. Processes represent active programs on your system, ranging from background services (like network management) to user applications. Understanding how to list, monitor, and manage these processes is crucial for system maintenance, troubleshooting, and ensuring optimal performance. Here’s an in-depth look at key commands for managing processes in Bash:


1. ps – List Active Processes

The ps (process status) command provides a snapshot of currently running processes. By default, ps shows only the processes associated with the current terminal session, but with additional options, it can display detailed information about all system processes.

  • Basic Usage:

    $ ps

    This command lists processes running in the current terminal session, showing details like the process ID (PID), terminal, CPU time, and command name.

  • View All Processes:

    • Use ps aux for a detailed list of all processes running on the system:

      $ ps aux
    • The aux options provide comprehensive information, including the user running each process, CPU and memory usage, and the command used to start the process. This is particularly helpful for spotting resource-hungry processes.

  • Common Fields in ps aux Output:

    • USER: The owner of the process.

    • PID: The unique process ID.

    • %CPU and %MEM: CPU and memory usage.

    • COMMAND: The command that started the process.

The ps command is great for obtaining a quick list of processes and identifying their PIDs, which are necessary for managing them further.


2. top and htop – Interactive Process Monitoring

The top and htop commands provide an interactive, real-time view of system processes. These tools continuously update to show current resource usage, making them ideal for monitoring system performance.

  • Basic Usage:

    • top displays a list of running processes sorted by CPU usage, memory consumption, or other criteria.

      $ top
    • htop is a more advanced, user-friendly alternative to top. It requires installation on some systems (sudo apt install htop), but it provides a color-coded, scrollable interface with additional features.

      $ htop
  • Using top:

    • CPU and Memory Usage: top shows an overview of CPU and memory usage at the top, with per-process details below.

    • Sorting: By default, top sorts processes by CPU usage. Press M to sort by memory, or P to return to CPU sorting.

    • Killing a Process: Press k while in top, then enter the PID of the process you want to stop.

  • Using htop:

    • Scroll and Navigate: Use the arrow keys to scroll through processes, and F3 to search for specific processes.

    • Kill Processes: Highlight a process and press F9 to bring up kill options, then choose a signal to terminate it.

    • Tree View: Press F5 to toggle tree view, which shows processes in a hierarchical structure, making it easier to identify parent-child relationships.

Both top and htop are invaluable for real-time monitoring, especially for identifying high-resource processes or diagnosing performance issues.


3. kill PID – Terminate a Process by Process ID (PID)

The kill command is used to terminate processes by their Process ID (PID), which can be found using commands like ps, top, or htop. Killing a process is necessary when it becomes unresponsive or when you need to free up system resources.

  • Basic Usage:

    $ kill PID

    This sends a SIGTERM (terminate) signal to the specified PID, allowing the process to end gracefully. The process is given time to save data and close open resources, making SIGTERM a gentle method for ending processes.

  • Force Termination:

    • Use kill -9 PID to send a SIGKILL (kill) signal, which forcibly stops the process immediately without allowing cleanup:

      $ kill -9 PID
    • SIGKILL should be used with caution, as it can lead to data loss if the process is performing critical operations.

  • List of Signals:

    • Use kill -l to list all available signals. Common signals include:

      • 1 (SIGHUP): Reloads the process.

      • 9 (SIGKILL): Forces termination.

      • 15 (SIGTERM): Gracefully terminates the process.

The kill command is essential for managing specific processes, especially those that have become unresponsive.


4. killall processname – Terminate All Instances of a Process by Name

The killall command allows you to terminate all processes with a specific name, rather than by PID. This is useful when you need to stop multiple instances of a process or terminate a program without searching for each PID individually.

  • Basic Usage:

    $ killall processname

    This command sends a SIGTERM signal to all processes with the specified name, requesting them to terminate gracefully.

  • Force Kill All Instances:

    • Use killall -9 processname to forcefully terminate all instances of a process by sending a SIGKILL signal:

      $ killall -9 processname

Examples:

  • killall firefox – Closes all running instances of the Firefox browser.

  • killall -9 apache2 – Forcefully stops all instances of the Apache server.

killall is particularly helpful for managing processes with multiple instances, such as stopping all web browser or server instances simultaneously.


Summary of Process Management Commands

  • ps aux – Lists all active processes with details like PID, CPU, and memory usage.

  • top / htop – Interactive tools for real-time monitoring of processes, allowing you to view and manage resource usage.

  • kill PID – Terminates a specific process by its PID.

  • killall processname – Terminates all instances of a process by name.

PreviousManaging PermissionsNextUsing Pipes and Redirection

Last updated 6 months ago

Was this helpful?

Page cover image