DevOps Learning Journey: Day 9 – Process Management and Background Jobs in Linux

Jyothi UradeJyothi Urade
6 min read

Hey everyone, 👋

Welcome to Day 9 of my DevOps learning series! Today I focused on understanding how Linux handles processes, especially how to manage, monitor, and troubleshoot them. This is a critical skill for anyone working in DevOps, especially when dealing with application performance or troubleshooting services.

Let’s break it down step by step 🛠️


🔍 What is a Process in Linux?

A process is any program or command currently running on your system. When you type a command like ping, it becomes a process until it finishes.

Processes can be:

· Foreground: Runs in the terminal and blocks other commands until it completes.

· Background: Runs in the background, allowing you to continue using the terminal.


⚙️ Foreground and Background Process Management

▶️ Run a Process in the Background

Add an ampersand & at the end:

sleep 30 &

This will run sleep in the background and immediately return control to your terminal.

⏸️ View Running Background Jobs

jobs

Lists current background tasks.

🔁 Bring Background Job to Foreground

fg

Resumes the most recent background job in the foreground.

📤 Send Foreground Process to Background

Use Ctrl + Z to suspend it, then:

bg

To resume it in the background.

🛑 Stop or Kill a Process

Use Ctrl + C to stop a foreground job. Use kill to terminate a background job using its PID:

kill <PID>


📊 Monitoring Tools to View System Activity

1. top – Real-Time Dynamic View

top

· Displays a dynamic, real-time list of running processes.

· CPU, memory usage, process ID, uptime, and more get updated live every few seconds.

· You can sort by CPU or memory usage using keys like P or M.

· Use q to quit.

🧠 Dynamic nature: You can watch processes rise and fall in CPU/memory usage in real time. Ideal when troubleshooting performance spikes or memory leaks.

2. htop – Visual, Dynamic, and Interactive

sudo apt install htop
htop

· An improved, interactive version of top.

· Uses a colorful, real-time dashboard.

· You can navigate with arrow keys, search (with /), kill processes (press F9), and sort columns.

· Processes update dynamically every second.

🧠 Dynamic nature: Great for DevOps engineers because you can interact with running processes live without needing to retype commands.

3. ps – Snapshot of Processes

ps is used to display information about running processes. Here are the most commonly used forms:

🔹 ps

ps

· Shows only the processes associated with the current terminal session.

· Basic and limited.

🔹 ps -e

ps -e

· Shows all processes running on the system.

· Simpler format without user information.

🔹 ps aux

ps aux

· a: show all users

· u: show user info

· x: show processes not attached to a terminal

· Most commonly used. Provides detailed info (CPU/memory usage).

🔹 ps -ef

ps -ef

· -e: all processes

· -f: full-format listing (shows parent PID, start time, command)

· Preferred for scripting and automation because of its consistent output.

✅ When to Use Which:

· Use ps alone to check your own terminal’s tasks.

· Use ps -e or ps -ef when writing scripts or debugging.

· Use ps aux for a readable snapshot of all running processes with resource usage.

🔍 Example with grep:

ps aux | grep apache2


🔢 Setting Process Priority with nice and renice

In Linux, each process has a priority. The nice value determines how much CPU time it gets — lower means higher priority.

nice – Start a Process with Priority

nice -n <value> command

· Range: -20 (highest priority) to 19 (lowest priority)

· Default is 0

Example:

nice -n 10 python3 myscript.py

Runs the script with a lower priority to avoid hogging CPU.

renice – Change Priority of Running Process

renice -n <new-value> -p <PID>

Example:

renice -n 5 -p 2345

🧠 DevOps Scenario: Running heavy backup or log parsing scripts at low priority during working hours to avoid slowing down live services.


💀 Killing and Managing Processes

kill

Send a signal to a specific process (PID):

kill 1234

killall

Kill all processes by name:

killall nginx


📁 Resource Usage Commands

1. free -h – Memory Usage

free -h

Shows total, used, and free memory.

2. df -h – Disk Usage

df -h

Displays disk space used by partitions.

3. du -sh <directory> – Folder Size

du -sh /var/log

Shows how much space a specific folder is using.


🔎 Why It Matters for DevOps

In real-world DevOps scenarios, you use these skills to:

· Restart stuck applications

· Identify high CPU/memory processes

· Troubleshoot production incidents

· Kill zombie processes

· Script automated monitoring tools

These commands are the building blocks before diving into tools like Prometheus, Grafana, Nagios, etc.


🧰 awk, sed, and grep – Text Processing Power Tools

These are powerful tools to search, filter, and transform text — especially useful when working with logs, CSVs, or config files.

🔍 grep – Search for Patterns

grep 'error' logfile.txt

Shows lines that contain the word “error”.

With ps:

ps aux | grep nginx

🪄 awk – Pattern-Based Reporting

awk '{print $1, $2}' file.txt

Prints first two columns.

Example:

ps aux | awk '{print $1, $2, $11}'

Lists user, PID, and command.

✂️ sed – Stream Editor (for replacing text)

sed 's/old/new/' file.txt

Replaces the first occurrence of “old” with “new” in each line.

Example:

cat config.txt | sed 's/dev/prod/g'

Updates environment names from dev to prod in a config file.

🧠 Real-World Usage:

· Automating log scanning for errors

· Cleaning up large files in CI/CD pipelines

· Generating custom reports from command outputs


🌐 curl vs wget – What’s the Difference?

✅ wget

· Mainly used for downloading files

· Simple and robust

· Can resume downloads

wget [options] [url]

✅ curl

· More flexible: works with HTTP, FTP, and APIs

· Supports POST, PUT, DELETE methods

· Can send headers and JSON payloads

curl https://example.com

Example of API Testing with curl:

curl -X POST -H "Content-Type: application/json" -d '{"name":"Pooja"}' https://api.example.com/users

🧠 DevOps Tip: Use wget when downloading software, and curl when working with REST APIs or testing endpoints.


📘 Summary: What I Learned Today

· The difference between foreground and background jobs

· How to pause, resume, and kill processes

· Monitoring system performance with top, htop, and ps

· How to analyze resource usage using free, df, and du

· Practical troubleshooting tips DevOps engineers use daily


Stay tuned for Day 10.

✨ Happy Learning,
👩‍💻 Jyothi Urade | #FromCloudToOps

0
Subscribe to my newsletter

Read articles from Jyothi Urade directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jyothi Urade
Jyothi Urade