Processes and Permissions

Understanding processes and permissions is essential for debugging and deployment.

Process management

bash
# See running processes
ps aux                    # all processes
ps aux | grep node        # filter by name

# Real-time process monitor
top                       # basic
htop                      # better (install: apt install htop)

# Kill a process
kill 1234                 # graceful (SIGTERM)
kill -9 1234              # force kill (SIGKILL)

# Find what's using a port
lsof -i :3000
# Then kill it
kill -9 $(lsof -t -i :3000)

File permissions

bash
ls -la
# -rwxr-xr-- 1 user group 1234 Mar 14 file.sh
#  │││ │││ │││
#  │││ │││ └── Others: read only
#  │││ └──── Group: read + execute
#  └────── Owner: read + write + execute

Changing permissions

bash
# Make a script executable
chmod +x deploy.sh

# Numeric: owner=rwx(7), group=rx(5), others=r(4)
chmod 754 deploy.sh

# Change ownership
chown user:group file.txt

Environment variables

bash
# Set for current session
export API_KEY="sk-abc123"

# Use in commands
echo $API_KEY

# Set for a single command
DATABASE_URL="postgres://..." node server.js

# Persistent: add to ~/.bashrc or ~/.zshrc
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc