Beneath the Cloud

Linux Processes, Signals & Memory

Draft · Linux verification pending

Use one terminal to start, inspect, pause, resume, and stop a process, then compare memory use with a 20 MiB allocation.

Before you start

A process is a running program. It has an ID, uses memory, and receives signals that control its lifecycle.

program → running process → state + memory

               signals

Use one Bash terminal on Linux throughout this lab. Allow about 15–20 minutes. No network setup or downloads are needed.

Check the tools:

command -v sleep ps python3

Each should print a path. On Ubuntu, if ps or Python is missing, install them with sudo apt install procps python3.

1. Start a process

sleep 1800 &
process_pid=$!

sleep waits for 30 minutes. The & leaves it running in the background so you can keep typing. $! is the background process’s ID; we save it as process_pid.

Run the steps in order in this same terminal. If the process expires, start this step again to get its new PID.

2. Look at it

ps -p "$process_pid" -o pid,stat,rss,comm

Read the four columns:

Column Meaning
PID The process ID
STAT Its state; S means sleeping while waiting
RSS Memory currently resident in RAM, in KiB
COMMAND The program name, here sleep

Sleeping is normal for this program. It still exists and uses some memory. Linux process fields

3. Pause it

kill -STOP "$process_pid"
ps -p "$process_pid" -o pid,stat,rss,comm

Look for T in STAT, meaning stopped. The PID stays the same, and pausing does not discard the process’s memory.

The command is named kill, but here it only sends a pause signal.

4. Resume it

kill -CONT "$process_pid"
ps -p "$process_pid" -o pid,stat,rss,comm

The stopped state should disappear. The program continues waiting. If ps catches the transition, run it again after a moment.

These are two different states: sleeping means waiting for something; stopped means execution has been suspended by a signal. Linux signals

5. Stop it

kill -TERM "$process_pid"
wait "$process_pid"
ps -p "$process_pid" -o pid,stat,rss,comm

SIGTERM terminates sleep. wait lets the shell finish collecting its exit status. A termination message or nonzero status is normal here.

Check that the process row has disappeared. Unlike a pause, termination ends the process and lets Linux reclaim its resources.

6. Try a little memory

Now compare two small Python processes: one just waits; the other holds an extra 20 MiB. Both use the same interpreter, so we avoid confusing Python’s own memory use with the allocation.

Start the baseline and note its RSS:

python3 -c 'import time; time.sleep(1800)' &
baseline_pid=$!
ps -p "$baseline_pid" -o pid,rss,vsz,comm

Start the second process:

python3 -c 'import time; memory = b"x" * (20 * 1024 * 1024); time.sleep(1800)' &
memory_pid=$!
ps -p "$memory_pid" -o pid,rss,vsz,comm

The provided one-liner fills a 20 MiB buffer with x and keeps it alive while Python waits. You do not need to write a script.

Wait a moment and repeat each ps command before comparing: Python may still be starting when the first reading is taken.

  • RSS is memory currently resident in RAM. Look for an increase in the second process.
  • VSZ is virtual address space, not actual RAM consumption.

20 MiB is 20,480 KiB, but do not expect exactly that difference in RSS. Runtime activity and operating-system accounting affect the readings. Use your actual values; the buffer size is not itself a memory measurement.

7. Clean up

Stop both Python processes and check that their rows disappear:

kill -TERM "$baseline_pid" "$memory_pid"
wait "$baseline_pid" "$memory_pid"
ps -p "$baseline_pid,$memory_pid" -o pid,comm

A nonzero status from wait or an empty ps result is expected after termination. The processes’ private memory is released; you do not need a separate command to free the buffer.

No files or network resources were created. If you leave the lab early while sleep is paused, send it SIGCONT before SIGTERM, then wait for it as in step 5.

Architect View

A process can be waiting, paused, or gone. Those states have different implications for an application. Pausing retains its resources; terminating it ends its work. A real service may handle SIGTERM to finish work before exiting.

For capacity planning, inspect resident memory rather than treating virtual size as a RAM bill. More workers can require more memory, even when they run the same program.

Azure Connection

Applications inside an Azure Linux VM are processes too. Use ps to identify them and inspect their state and memory before deciding to restart the entire VM.

Continue with Create a Linux VM.