Linux Processes, Bash
& Serial Communication
Process management and permissions, I/O redirection and piping, Bash scripting, tmux, picocom, and the hardware utilities used daily in embedded development.
What is a Process?
A process is a program that is currently running. Every application you open becomes a process, and Linux manages all running processes using the kernel.
Every process gets a unique Process ID (PID):
Many Linux commands use the PID to identify and control a specific process.
| Command | Purpose |
|---|---|
ps | View running processes |
top | Live system monitor |
htop | Interactive process monitor |
kill | Stop a process |
jobs | Show background jobs |
fg | Bring a job to foreground |
bg | Resume a job in background |
Shows a snapshot of currently running processes.
ps # processes in this terminal
ps aux # all processes on the system
ps aux | grep picocom # check if picocom is runningps aux | grep openocd — verify that OpenOCD is running before attempting to debug. Helps catch the common "already running" conflict.top shows CPU, memory, and all running processes updated in real time. Press q to quit.
tophtop is an improved, colour-coded version of top with a more user-friendly interface. Install it if it isn't already present:
sudo apt install htop
htoptop or htop during a large firmware build to monitor CPU and memory usage in real time — useful for spotting runaway compilation jobs or memory pressure.Sends a signal to a process. By default it sends SIGTERM (graceful stop). Use -9 for an immediate forced termination.
kill 4187 # ask process 4187 to stop gracefully
kill -9 4187 # immediately force-terminate process 4187kill requests a clean stop. kill -9 is the force option — the process has no chance to save state or clean up. Use -9 only when the process is frozen.jobs — list background jobs
jobs
# Output: [1]+ Running python script.py &fg — bring to foreground
fg # bring most recent job to foreground
fg %1 # bring job number 1bg — continue in background
bg # resume the stopped job in backgroundCtrl+C vs Ctrl+Z
fg to resume after Ctrl+Z.Common Linux Signals
| Signal | Value | Purpose |
|---|---|---|
SIGINT | 2 | Interrupt a process (Ctrl+C) |
SIGTERM | 15 | Request graceful termination |
SIGKILL | 9 | Force terminate — cannot be caught |
SIGTSTP | 20 | Suspend a process (Ctrl+Z) |
SIGCONT | 18 | Continue a stopped process |
Linux File Permissions
Linux protects files using permissions that determine who can read, modify, or execute a file. Every file has three permission groups:
Every file has three groups of permissions. Each group can have read (r=4), write (w=2), and execute (x=1) — or none (-).
ls -l
# -rwxr-xr-- 1 satwik satwik 1234 Jun 1 script.shSymbolic Mode
chmod +x script.sh # add execute permission
chmod -x script.sh # remove execute permissionNumeric Mode
chmod 644 file # rw-r--r-- (common for text files)
chmod 755 script.sh # rwxr-xr-x (common for scripts)
chmod 777 file # rwxrwxrwx (avoid — grants full access to everyone)| Permission | Mode | Result | Use Case |
|---|---|---|---|
chmod 644 | rw-r--r-- | Owner: read+write. Others: read | Config files, source code |
chmod 755 | rwxr-xr-x | Owner: all. Others: read+exec | Shell scripts, binaries |
chmod 777 | rwxrwxrwx | Everyone has full access | Avoid unless absolutely needed |
chmod +x flash.sh && ./flash.sh — make the flash script executable, then run it immediately.Changes the owner (and optionally the group) of a file or directory.
sudo chown satwik project.txt # change owner
sudo chown satwik:developers file.txt # change owner and groupls -l shows current permissions. chmod changes permissions. chown changes ownership. 644 is common for files, 755 for scripts and directories.stdin / stdout / stderr
Every Linux program communicates using three standard streams. Understanding these is the foundation of redirection and pipes.
By default all three streams connect to the terminal. Redirection changes where each stream goes.
| Stream | Number | Default source/dest | Purpose |
|---|---|---|---|
stdin | 0 | Keyboard | Input data for the program |
stdout | 1 | Terminal | Normal program output |
stderr | 2 | Terminal | Error messages only |
Output Redirection
> — Overwrite>> — AppendInput Redirection
sort < numbers.txt # sort reads from file instead of keyboardPipes ( | )
A pipe sends the stdout of one command directly into the stdin of another — without creating any temporary files.
Pipes chain commands together. The output of each command flows directly into the next.
ps aux | grep python # find running Python processes
find . -name "*.c" | wc -l # count all C source files
dmesg | tail # see the last kernel messagescmd1 | cmd2 | cmd3.Error Redirection
cat missing.txt 2> errors.txt # redirect only errors to file
make > build.log 2>&1 # redirect both stdout AND stderr to same fileThe 2>&1 syntax means: "redirect file descriptor 2 (stderr) to wherever file descriptor 1 (stdout) is going." This is used constantly to capture complete build logs.
west build > build.log 2>&1 — capture the entire build output (including errors) into a single log file. Then grep "error" build.log to find the failures.Bash Shell
Bash (Bourne Again SHell) is the default command-line shell on most Linux systems. It reads commands from the user, executes them, and displays the results. It also runs shell scripts — files containing lists of commands to automate tasks.
Shell Scripts
A shell script is a text file containing Linux commands. Instead of typing the same commands repeatedly, save them once and execute whenever needed.
#!/bin/bash
echo "Building..."
make
echo "Done"Shebang — the first line
The #!/bin/bash line tells Linux which interpreter should run the script. It must be the very first line.
Make it executable and run it
chmod +x build.sh # make executable (only needed once)
./build.sh # run the scriptComments
Lines beginning with # are comments. They are ignored during execution but improve readability.
# Build firmware for ESP32
makeVariables & echo
PROJECT=ESP32 # assign variable (no spaces around =)
echo $PROJECT # use with $ prefix → outputs: ESP32
PORT=/dev/ttyUSB0
echo "Connecting to $PORT"
read NAME # read user input
echo "Hello $NAME"= when assigning. Always use $ prefix when reading a variable. Variables can store paths, names, numbers, or command output.Exit Status
Every command returns an exit status (also called a return code) when it finishes. This is the most important way scripts detect success or failure.
make
echo $? # 0 = success, non-zero = errorset -euo pipefail
Professional shell scripts begin with this line to make them safe and reliable:
set -euo pipefail| Flag | Effect |
|---|---|
-e | Stop the script immediately if any command fails |
-u | Treat any undefined variable as an error |
pipefail | If any command in a pipe fails, the entire pipeline fails |
Complete Embedded Script Example
#!/bin/bash
set -euo pipefail
west build
west flash
picocom -b 115200 /dev/ttyUSB0This script builds firmware, flashes it to the board, and opens the serial monitor. If any step fails, the script stops immediately rather than continuing with a broken state.
>overwrites a file with command output.>>appends output to a file (keeps existing content).|connects commands — output of one becomes input of next.2>&1captures both stdout and stderr to the same destination.#!/bin/bashmust be the first line of every shell script.set -euo pipefailis best practice for reliable scripts.
tmux lets you run multiple terminal sessions inside one window. Unlike a normal terminal, a tmux session keeps running even if you disconnect from SSH or close the terminal.
Session Commands
tmux new -s embedded # create session named "embedded"
tmux ls # list all running sessions
tmux attach -t embedded # re-attach to "embedded" sessionTo detach (leave session running in background): press Ctrl+B then D.
Keyboard Shortcuts (prefix: Ctrl+B)
| Shortcut | Action |
|---|---|
Ctrl+B C | Create a new window |
Ctrl+B % | Split pane vertically |
Ctrl+B " | Split pane horizontally |
Ctrl+B Arrow | Move between panes |
Ctrl+B D | Detach (session stays running) |
west build. Pane 2 → west flash. Pane 3 → picocom -b 115200 /dev/ttyUSB0. All three stay running simultaneously — even over SSH.UART & Serial Device Files
UART (Universal Asynchronous Receiver/Transmitter) is the hardware interface used for serial communication — transferring data one bit at a time between two devices.
When the board is connected, Linux automatically detects it and creates a device file — the address you use to open a serial connection.
Serial Device Files
| Device | Created by | Example boards |
|---|---|---|
/dev/ttyUSB0 | USB-to-UART chips (CP2102, CH340, FT232) | ESP32, ESP8266 |
/dev/ttyACM0 | Native USB CDC devices | STM32 USB CDC, Arduino Leonardo |
Baud Rate
The baud rate is the communication speed. Both sides must use the same value. Common values: 9600, 115200, 230400, 460800. Most embedded projects use 115200.
picocom -b 115200 /dev/ttyUSB0 # open serial monitor
picocom -b 115200 --logfile serial.log /dev/ttyUSB0 # + save to logTo exit: press Ctrl+A then Ctrl+X.
dialout Group — Required for Serial Access
Serial devices are only accessible to members of the dialout group. If picocom gives a "Permission denied" error, add yourself to the group:
groups # check your current groups
sudo usermod -aG dialout $USER # add yourself to dialoutusermod. The group membership only takes effect in new login sessions — the terminal you ran the command in won't be updated until you re-login.dmesg & lsusb
Shows messages from the Linux kernel. Most useful immediately after plugging in a board — it shows whether Linux detected the device and what device file was created.
dmesg | tail # show last kernel messages (use after plugging in board)Lists all USB devices currently connected to the system. Use it to verify Linux has detected your board.
lsusbss & tree
ss -tln # show listening TCP ports
ss -tlnp # show ports with process namesUseful for debugging networking services — verify which ports your embedded server, MQTT broker, or debug interface is listening on.
tree # full tree from current directory
tree -L 2 # limit depth to 2 levelsEssential for understanding unfamiliar project structures.
Typical Embedded Workflow
This is the standard sequence every embedded developer follows when connecting a board for the first time:
sudo usermod -aG dialout $USER then log out and back in. You only need to do this once per machine.Complete Command Reference
| Command | Purpose | Part |
|---|---|---|
pwd | Print current directory | Part 1 |
ls / ls -la | List files (including hidden) | Part 2 |
cd | Change directory | Part 2 |
mkdir / rmdir | Create / remove directory | Part 2 |
touch | Create empty file | Part 2 |
cp / mv / rm | Copy / Move / Delete | Part 2 |
cat / less | View file / page-by-page | Part 3 |
head / tail | First / last lines; tail -f for live | Part 3 |
find | Find files by name or type | Part 3 |
grep / rg | Search text inside files | Part 3 |
du / df | Folder size / disk free space | Part 3 |
ps / top / htop | View / monitor processes | Part 4 |
kill | Stop a process by PID | Part 4 |
chmod / chown | Change permissions / owner | Part 4 |
> / >> / | | Redirect output / pipe | Part 5 |
2>&1 | Merge stderr into stdout | Part 5 |
tmux | Persistent terminal sessions | Part 6 |
picocom | Serial terminal for boards | Part 6 |
dmesg | Kernel messages (device detection) | Part 6 |
lsusb | List connected USB devices | Part 6 |
ss | Network sockets / open ports | Part 6 |
tree | Directory tree visualisation | Part 6 |
- These commands are used daily when working with Zephyr RTOS, ESP-IDF, STM32Cube, PlatformIO, Git, CMake, OpenOCD, West, SSH, and Raspberry Pi.
- Reading alone is not enough — practice each command in a real terminal on your own projects.
- The
man command(manual) is available for every command:man grep,man find, etc. - Combine commands with pipes — real-world usage chains multiple tools together.
- Use
tmuxfrom day one when working on embedded Linux projects over SSH. - Always run
dmesg | tailfirst when a board isn't detected — it tells you exactly what happened.
Module 0.4 (Parts 4–6) — Processes, Permissions, Bash & Serial · Embedded Systems Foundations