ctrlc

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

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

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
51/100Fair
Development Activity40
Maintenance24
Community60
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture72
Code Quality74
Innovation65
Learning Curve85

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

26,876

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
Rust89%
Updated today
Rust
91%
Apache 2.0

herdr

AI Agents · Developer Tools

30,468

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
83
Repo Health
84
Technical
76
Dependency
Built with
Rust91%
Updated today
Rust
72%
Other

iii

Developer Tools · Devops

18,604

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

View details
86
Repo Health
85
Technical
69
Dependency
Built with
Rust72%
TypeScript17%
Updated yesterday
Rust
72%
Apache 2.0

mesh-llm

AI Development · AI Agents

3,258

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
83
Repo Health
91
Technical
70
Dependency
Built with
Rust72%
TypeScript16%
Updated today
Python
100%
Other

OpenBB

Databases · Analytics · Invoicing Finance

72,027

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

View details
82
Repo Health
80
Technical
68
Dependency
Built with
Python100%
Updated 2 weeks ago
Rust
63%
MIT

PostgresML

Databases · AI Development

6,817

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

View details
51
Repo Health
76
Technical
65
Dependency
Built with
Rust63%
JavaScript11%
Updated 1 years ago
Rust
97%
Other

Zed

Developer Tools · Collaboration · Code Editors

88,861

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
73
Dependency
Built with
Rust97%
Updated today

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

Search