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

推荐订阅源

博客园 - 聂微东
宝玉的分享
宝玉的分享
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
博客园 - 【当耐特】
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
博客园 - 司徒正美
博客园 - Franky
爱范儿
爱范儿
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
Jina AI
Jina AI
量子位
博客园 - 叶小钗
博客园_首页
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

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.