Module 0.4 —
Assessment Answers
Complete answers for all three sections — multiple choice, short answer, and scenario-based questions on Linux command line for embedded systems.
-n 50 sets the line count; -f follows new lines in real time. Press Ctrl+C to stop.
rg is purpose-built for source code, searches recursively by default, and respects .gitignore.
SIGINT (signal 2) — interrupt request. The process can catch and handle it. Ctrl+Z sends SIGTSTP (suspend).
The process is paused, not killed. Use fg to bring it back or bg to continue it in the background.
Serial device files in /dev/ are owned by the dialout group. Without membership, access is denied unless you use sudo.
All three flags together make scripts safe: they fail loudly instead of continuing with broken state.
Press Ctrl+B first, then the command key. e.g., Ctrl+B D to detach, Ctrl+B % to split vertically.
644 = rw-r--r--. Owner (6=4+2): read+write. Group/Others (4): read only. Standard for config files.
-t TCP, -l listening only, -n numeric ports, -p process names. Use this to debug which program is using a port.
Run immediately after plugging in a board. Linux logs the driver load and device file assignment (/dev/ttyUSB0) here.
picocom is a lightweight serial terminal designed for direct terminal use. Unlike the Arduino IDE's Serial Monitor, it works seamlessly over SSH, inside tmux sessions, and in automation scripts. It allows serial data to be logged, redirected, and processed using standard Linux commands.
picocom | grep ERROR filters live serial data.find . -name "*.c" -exec wc -l {} \; | sort -rn | head -10How each part works
| Part | Meaning |
|---|---|
find . -name "*.c" | Search all .c files from current directory |
-exec wc -l {} \; | Run wc -l (line count) on every file found |
| sort -rn | Sort numerically (-n) in reverse/descending (-r) order |
| head -10 | Keep only the top 10 results |
Workflow summary
- 1.Find all
.csource files. - 2.Count lines in each file.
- 3.Sort by line count, largest first.
- 4.Display only the top 10 files.
> — OverwriteRedirects stdout to a file. If the file exists, its content is erased first. If it doesn't exist, it is created.
>> — AppendAdds new output to the end of an existing file. Does not erase previous content. Creates the file if it doesn't exist.
> for fresh output you want to overwrite on each run (e.g., latest build status). Use >> for cumulative logs where you need to keep all history (e.g., firmware run logs).A practical tmux setup uses three panes running simultaneously:
tmux new -s stm32-debug # create a named session
# Ctrl+B % → split to get Pane 2
# Ctrl+B " → split to get Pane 3| Pane | Command | Purpose |
|---|---|---|
| Pane 1 | make / pio run | Build firmware — see compile errors immediately |
| Pane 2 | st-flash write / west flash | Flash the latest build to the board |
| Pane 3 | picocom -b 115200 /dev/ttyACM0 | Monitor UART output from the STM32 |
Ctrl+B D) and reconnect later with tmux attach -t stm32-debug — the build and monitor stay running.In Linux, every process has numbered file descriptors: stdout = 1 and stderr = 2. The notation 2>&1 means: "redirect file descriptor 2 (stderr) to wherever file descriptor 1 (stdout) currently points."
make > build.log 2>&1 # stdout goes to file, then stderr follows stdoutWhy the order matters
| Command | Result |
|---|---|
cmd > out.txt 2>&1 | stdout → file, then stderr → same file ✓ Both captured |
cmd 2>&1 > out.txt | stderr → terminal (old stdout), stdout → file ✗ Errors on screen |
west build > build.log 2>&1 — captures everything including compiler errors into one log file. Then grep error build.log to find failures quickly.Work through these steps in order — each one narrows down the cause:
dmesg | tailusb X-X: new full-speed USB device followed by cp210x converter now attached to ttyUSB0. If nothing appears, Linux didn't detect the hardware at all — try a different USB cable or port.ls /dev/ttyUSB* /dev/ttyACM*lsusbgroups $USERls -l /dev/ttyUSB0sudo usermod -aG dialout $USER then log out and back in. Driver not installed → sudo apt install cp210x-dkms. Cable only provides power (no data lines) → swap for a data USB cable.Primary answer — using Ripgrep:
rg -n TODO| Flag | Meaning |
|---|---|
rg | Run Ripgrep (searches recursively by default) |
-n | Show line numbers alongside each match |
TODO | The search pattern |
Alternative — using grep:
grep -rn TODO .rg automatically skips build/, .git/, and other directories in .gitignore, so results contain only real source code matches — not false positives from build artifacts.stty -F /dev/ttyACM0 921600 raw && timeout 30 cat /dev/ttyACM0 > capture.log| Part | Purpose |
|---|---|
stty -F /dev/ttyACM0 921600 raw | Configure serial port: set baud rate 921600, enable raw mode (no line processing) |
&& | Run the next command only if stty succeeded (exit status 0) |
timeout 30 | Automatically stop after exactly 30 seconds |
cat /dev/ttyACM0 | Read raw bytes from the serial device file |
> capture.log | Redirect all output into the log file |
raw mode, the terminal driver processes the data — interpreting control characters, adding newlines, etc. raw passes bytes through completely unmodified, which is what you want for binary firmware logs.tmux new -s testInside the tmux session, start your test script or long-running process normally:
./run_long_test.shDetach from the session (the process keeps running in the background):
Ctrl+B, then D # session keeps running after SSH disconnectsReconnect at any time — even after SSH drops:
tmux attach -t testModule 0.4 — Linux Command Line Assessment Answers · Embedded Systems Foundations