惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
H
Help Net Security
V
Visual Studio Blog
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
MyScale Blog
MyScale Blog
The Cloudflare Blog
Martin Fowler
Martin Fowler
D
Docker
腾讯CDC
F
Fortinet All Blogs
雷峰网
雷峰网
GbyAI
GbyAI
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Blog — PlanetScale
Blog — PlanetScale
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
博客园 - 叶小钗

Stonecharioteer on Tech

I Traced My Traffic Through a Home Tailscale Exit Node What Was I Reading Last? In Three Not-So-Easy Pieces Dogfooding Is Hard Code blocks in your books, finally GoForGo v0.9.0 Merrilin - We built an app to read books I use a Macbook now Data Structures & Algorithms - Preparing for Interviews Using a local DNS namespace for local service discovery Direction KOllector - Publishing KOReader Highlights gbt: branches touched in the last 24 hours A Soiree into Symbols in Ruby Some Smalltalk about Ruby Loops Ruby Blocks Returning from Ruby Blocks, Procs and Lambdas My Linux Laptop Finally Works: How Claude Helped Me Fix Years of Annoyances TIL: Watchexec - Modern File Watching for Development Workflows A Less Busy Mind GoForGo - Learn Go through live examples Migrating My Old Blog to Hugo with Claude The Qtile Window Manager: A Python-Powered Tiling Experience Read the RFCs that Built the Internet Py-x-Protobuf - Or How I Learned to Stop Worrying and Love Protocol Buffers Python Reverse a List New Beginnings Leaving ChainSafe Systems Screen Lock for Cinnamon Desktop using Zenity and Terminal Commands Crews Not Teams A System for Getting Better at LeetCode
TIL: Kill Command with Readable Signal Arguments
2020-11-21 · via Stonecharioteer on Tech

Today I discovered a simple but important improvement to using the kill command that makes process management safer and more readable.

Using Readable Signal Names

Instead of memorizing and using numeric signal codes, the kill command accepts human-readable signal names:

Traditional Numeric Approach:

1
2
3
4
5
# Hard to remember and error-prone
kill -9 1234    # SIGKILL
kill -15 1234   # SIGTERM
kill -19 1234   # SIGSTOP
kill -18 1234   # SIGCONT

Better Readable Approach:

1
2
3
4
5
# Clear, self-documenting commands
kill -KILL 1234   # Force terminate process
kill -TERM 1234   # Graceful termination request
kill -STOP 1234   # Pause process execution
kill -CONT 1234   # Resume paused process

Common Signal Names

Process Termination:

  • -TERM (15): Polite termination request - allows cleanup
  • -KILL (9): Immediate forceful termination - no cleanup possible
  • -QUIT (3): Quit with core dump for debugging

Process Control:

  • -STOP (19): Pause process execution (cannot be caught or ignored)
  • -TSTP (20): Terminal stop signal (Ctrl+Z equivalent)
  • -CONT (18): Resume stopped process execution

Application Signals:

  • -HUP (1): Hangup - often used to reload configuration
  • -USR1 (10): User-defined signal 1 - application-specific behavior
  • -USR2 (12): User-defined signal 2 - application-specific behavior

Benefits of Readable Names

Safety and Clarity:

1
2
3
4
5
# Immediately clear what this does
kill -TERM $(pgrep myapp)

# vs unclear numeric version
kill -15 $(pgrep myapp)

Self-Documenting Scripts:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#!/bin/bash
# Graceful service restart script

PID=$(pgrep myservice)
if [ -n "$PID" ]; then
    echo "Requesting graceful shutdown..."
    kill -TERM $PID

    # Wait for graceful shutdown
    sleep 5

    # Force kill if still running
    if kill -0 $PID 2>/dev/null; then
        echo "Forcing termination..."
        kill -KILL $PID
    fi
fi

Reduced Errors:

Using readable names eliminates the risk of accidentally using the wrong signal number, which could have unintended consequences on system stability.

This simple practice makes process management commands more maintainable and reduces the cognitive load of remembering numeric signal codes.