</>
Skip to content
Bash lessons (25/29)

Bash — Processes

Listing processes

ps aux               # All processes
ps -ef               # Full format
ps aux | grep name   # Find process
top                  # Interactive monitor
htop                 # Better monitor

Background processes

#!/bin/bash

# Run in background
long_command &

# See background jobs
jobs

# Bring to foreground
fg %1

# Suspend and background
# Ctrl+Z
bg %1

Signals

#!/bin/bash

# Common signals
kill -TERM PID    # Terminate (default)
kill -INT PID     # Interrupt (Ctrl+C)
kill -KILL PID    # Force kill (Ctrl+\)
kill -HUP PID     # Hangup (reload config)

# Trap signals
trap 'echo "Caught SIGINT"' INT
trap 'echo "Cleaning up"' EXIT

Process substitution

#!/bin/bash

diff <(ls dir1) <(ls dir2)
while read line; do
    echo "$line"
done < <(command)

Mini Practice

Write Bash code that:

  1. Lists and finds processes
  2. Runs a command in the background
  3. Uses trap for cleanup
  4. Uses process substitution

Up Next

In the next lesson, you'll learn about Environment Variables — configuring your shell.

Related Topics

Frequently Asked Questions about Processes

What is Processes in Bash?

Processes is a fundamental concept in Bash. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Processes?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Processes.

Why is Processes important in Bash?

Processes is essential for Bash development. Understanding this concept will help you write better code and solve real-world problems more effectively.