ctrlc

Simple, cross-platform Ctrl-C signal handling for Rust projects

Library
Cargo
v3.5.2
669 stars
MIT/Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
48 /100 Fair
Development Activity 28
Maintenance 24
Community 60
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
74 /100 Good
Architecture 72
Code Quality 74
Innovation 65
Learning Curve 85

ctrlc is a small Rust crate that wraps platform-specific signal handling behind a single set_handler function, letting applications register a closure to run when the user presses Ctrl-C. It abstracts over Unix signal APIs (via nix), Apple’s dispatch2, and Windows console control handlers (via windows-sys) so the same code works unmodified across platforms.

With the termination feature enabled, it also intercepts SIGTERM and SIGHUP on Unix, making it a common building block for CLI tools and long-running services that need graceful shutdown behavior.

What You Get

  • A single cross-platform set_handler API that abstracts Unix signals, Windows console events, and Apple dispatch2
  • Optional termination feature to also catch SIGTERM and SIGHUP on Unix for graceful shutdown
  • A minimal, dependency-light design using platform-native signal APIs rather than a heavyweight abstraction layer
  • Channel-friendly design (works naturally with std::sync::mpsc or any closure-based notification pattern)
  • Dual MIT/Apache-2.0 licensing for unrestricted use in any Rust project

Common Use Cases

  • Gracefully shutting down a long-running CLI tool or daemon when the user presses Ctrl-C
  • Flushing buffers, closing file handles, or committing in-progress work before exit in a server process
  • Coordinating a clean stop signal across worker threads in a multi-threaded Rust application
  • Building interactive CLI tools that need to intercept interrupts without terminating immediately

Under The Hood

Architecture — The crate’s public surface is a thin, 148-line src/lib.rs exposing set_handler, which delegates to src/platform/mod.rs (20 lines) — a compile-time platform dispatch to either src/platform/unix/mod.rs (142 lines, uses the nix crate’s signal APIs and, on Apple targets, dispatch2) or src/platform/windows/mod.rs (81 lines, uses windows-sys’s console control handler APIs). Errors are centralized in src/error.rs (54 lines) as a small Error enum covering multiple-registration and platform-specific failure cases.

Tech Stack — Pure Rust, edition 2021, targeting Rust 1.69+. Platform-conditional dependencies keep the footprint minimal: nix (signal feature only) on Unix, dispatch2 on Apple targets, windows-sys (Win32 Foundation/Threading/Security/Console features) on Windows. No async runtime dependency — the handler runs synchronously via OS-level signal delivery.

Code Quality — Tests are organized under tests/main/ with a dedicated regression test (issue_97.rs) referencing a specific historical bug, and both test binaries run without the default harness (harness = false) to control signal-handling test isolation, a sign of the maintainer being deliberate about the risks of testing signal-sensitive code. The crate carries an explicit “passively-maintained” badge and 11 tagged releases going back to 2015, with releases still landing in 2025-2026, indicating long-term stability rather than abandonment.

API Design — The public API is intentionally minimal: one function (set_handler) taking a closure, mirroring how developers already use std::thread::spawn or channel callbacks, so integration requires no new concepts. The optional termination Cargo feature flag lets consumers opt into broader signal coverage (SIGTERM/SIGHUP) without changing the call site, keeping the default behavior narrow and predictable.

Used by 7 apps in this directory

Rust
89%
Apache 2.0

Graphite

Code Editors · Design Tools

27,377

A free, open source procedural 2D design tool that unifies vector, raster, motion graphics, and generative art in a single node-based nondestructive workflow.

View details
84
Repo Health
77
Technical
70
Dependency
Built with
Rust 89%
Updated 5 days ago
Rust
94%
Apache 2.0

herdr

AI Agents · Developer Tools

41,057

A terminal-native agent multiplexer that runs Claude, Codex, Gemini, and other coding agents side by side in real, persistent panes you can detach from and reattach to from anywhere.

View details
84
Repo Health
84
Technical
72
Dependency
Built with
Rust 94%
Updated 5 days ago
Rust
73%
Other

iii

Developer Tools · Devops

18,814

Compose, extend, and observe every backend service in real time using three primitives: Workers, Functions, and Triggers.

View details
87
Repo Health
85
Technical
65
Dependency
Built with
Rust 73%
TypeScript 16%
Updated 5 days ago
Rust
71%
Apache 2.0

mesh-llm

AI Agents · AI Development

3,463

Mesh LLM pools GPUs and memory across every machine you own into one OpenAI-compatible API, so agents tap distributed compute instead of a single GPU box or a metered cloud bill.

View details
84
Repo Health
91
Technical
69
Dependency
Built with
Rust 71%
TypeScript 13%
Python 10%
Updated 4 days ago
Python
100%
Other

OpenBB

Analytics · Databases · Invoicing Finance

73,553

The AI Workspace for Finance: Connect Data, Run AI Agents, Build Analytics

View details
77
Repo Health
80
Technical
67
Dependency
Built with
Python 100%
Updated 4 days ago
Rust
63%
MIT

PostgresML

AI Development · Databases

6,825

Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.

View details
51
Repo Health
76
Technical
64
Dependency
Built with
Rust 63%
JavaScript 11%
Updated 1 years ago
Rust
98%
Other

Zed

Code Editors · Collaboration · Developer Tools

90,979

High-performance, multiplayer code editor built in Rust by the creators of Atom and Tree-sitter, with native AI integration and real-time collaboration.

View details
94
Repo Health
88
Technical
72
Dependency
Built with
Rust 98%
Updated 4 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers