Skip to content

VOL 00 / CH 01 / LESSON 05

1.5 Exploring Your System (Experiment) ​

Prerequisites: Basic models of programs, processes, threads, and memory

Estimated time: 15–25 minutes

You are ready to continue when: you can start, observe, and clean up a test process, and understand the CPU and memory overview of your machine

Now inspect this machine on your own. The entire experiment will only involve the processes and temporary directories you create yourself; don't touch any unfamiliar PID.

Step 1: Platform and Tools ​

Linux:

bash
uname -a
command -v ps free python3

macOS:

bash
sw_vers
command -v ps vm_stat python3

Windows PowerShell:

powershell
$PSVersionTable.PSVersion
Get-Command Get-Process,python

Type: runnableNote: The availability of command paths and versions determines whether subsequent fields are available. Stop immediately if Python is missing; do not include installation steps in this exercise.

Step 2: View CPU and Memory ​

Linux:

bash
lscpu | sed -n '1,12p'
free -h

macOS:

bash
sysctl -n machdep.cpu.brand_string
sysctl -n hw.logicalcpu
vm_stat

Windows PowerShell:

powershell
Get-CimInstance Win32_Processor | Select-Object Name,NumberOfCores,NumberOfLogicalProcessors
Get-CimInstance Win32_OperatingSystem | Select-Object TotalVisibleMemorySize,FreePhysicalMemory

Record the number of logical CPUs. The units and definitions of the memory field vary by platform; do not directly compare the raw numbers in the table.

Step 3: Start, Observe, and Clean Up ​

Bash:

bash
python3 -c 'import time; time.sleep(30)' &
pid=$!
ps -p "$pid" -o pid,ppid,stat,%cpu,%mem,etime,command
kill "$pid"
wait "$pid" 2>/dev/null || true
if ps -p "$pid" >/dev/null 2>&1; then
  echo "cleanup failed: PID $pid still exists" >&2
  exit 1
fi
echo "cleanup complete"

PowerShell:

powershell
$process = Start-Process python -ArgumentList '-c "import time;time.sleep(30)"' -PassThru
Get-Process -Id $process.Id
Stop-Process -Id $process.Id
$process.WaitForExit()
"cleanup complete"

Type: runnableObservation: The Bash output shows the test PID, parent process, state, and elapsed time. PowerShell displays different default columns; before stopping the process, use Get-CimInstance Win32_Process -Filter "ProcessId = $($process.Id)" to inspect ParentProcessId. Both command groups should end with cleanup complete. After the PID exits, it may be quickly reused by other processes, so the cleanup judgment is only suitable for immediate execution after the experiment.

Step 4: Optional Port Experiment ​

On Linux, start a local HTTP service in a temporary directory, listening only on loopback. Save the following as explore-port.sh, then run bash explore-port.sh; the exit cleanup relies on this separate script exiting:

bash
set -e
workdir=$(mktemp -d)
server_pid=
cleanup() {
  if [[ -n "$server_pid" ]]; then
    kill "$server_pid" 2>/dev/null || true
    wait "$server_pid" 2>/dev/null || true
  fi
  rm -r -- "$workdir"
}
trap cleanup EXIT
trap 'exit 130' INT
trap 'exit 143' TERM

printf 'atlas\n' > "$workdir/index.html"
port=$(python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1]); s.close()')
python3 -m http.server "$port" --bind 127.0.0.1 --directory "$workdir" >"$workdir/http.log" 2>&1 &
server_pid=$!
sleep 1
if ! kill -0 "$server_pid" 2>/dev/null; then
  sed -n '1,20p' "$workdir/http.log" >&2
  exit 1
fi
curl -fsS "http://127.0.0.1:$port/"
ss -ltnp "sport = :$port" || true

Type: runnableEnvironment: Linux, Bash, Python 3, curl, ss Observation: Python first requests an available port on the loopback address; curl outputs atlas, and ss shows the listener on 127.0.0.1. There is a very small race window between requesting the port and starting the service, and the script will first print logs if it fails. The EXIT trap cleans up after a normal exit or a command failure that exits the script. INT and TERM first exit with the corresponding status, then trigger cleanup. SIGKILL cannot be trapped; check for leftover resources after a forced termination. This server is only for local experiments and is not suitable for production environments.

Troubleshooting Order ​

  1. Can command -v or Get-Command find each required program?
  2. Is the error due to command syntax, permissions, missing tools, or port conflicts?
  3. Does the process still exist? First, clean up using the saved PID.
  4. Your output differs from the example, could it be a platform difference or a model error? Record specific fields before deciding.

Acceptance ​

By the end of the experiment, at least four verifiable records should remain: the number of logical CPUs, the PID and PPID of the test process, a snapshot of process states, and the successful cleanup output. Additionally, check that the test process and temporary directory have disappeared. The emphasis here is on evidence, not on whether the output matches a screenshot exactly.

Confirm that the test process and temporary directory are gone. Continue with Terminal Basics, where we will break down each command, parameter, and path used previously.

References ​

Built with VitePress | Software Systems Atlas