{"id":13527686,"url":"https://github.com/thefrontside/ctrlc-windows","last_synced_at":"2025-04-14T23:43:11.629Z","repository":{"id":45888877,"uuid":"308363658","full_name":"thefrontside/ctrlc-windows","owner":"thefrontside","description":"Send a CTRL-C event to a Windows console application","archived":false,"fork":false,"pushed_at":"2024-12-24T20:43:05.000Z","size":289,"stargazers_count":9,"open_issues_count":1,"forks_count":2,"subscribers_count":5,"default_branch":"v2","last_synced_at":"2025-03-28T11:43:22.153Z","etag":null,"topics":["concurrency","nodejs","windows"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thefrontside.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-29T15:03:36.000Z","updated_at":"2024-12-24T20:39:14.000Z","dependencies_parsed_at":"2022-08-22T13:50:25.369Z","dependency_job_id":null,"html_url":"https://github.com/thefrontside/ctrlc-windows","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thefrontside%2Fctrlc-windows","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thefrontside%2Fctrlc-windows/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thefrontside%2Fctrlc-windows/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thefrontside%2Fctrlc-windows/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thefrontside","download_url":"https://codeload.github.com/thefrontside/ctrlc-windows/tar.gz/refs/heads/v2","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248432045,"owners_count":21102306,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["concurrency","nodejs","windows"],"created_at":"2024-08-01T06:01:56.995Z","updated_at":"2025-04-14T23:43:11.612Z","avatar_url":"https://github.com/thefrontside.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# ctrlc-windows\n\nSend CTRL-C to a Windows console application\n\nLong running stateful processes like servers often hold a lot of\nsystem resources that they need to operate. These are things like\ncommunication ports, file descriptors, database connections, etc... At some point,\nwhen it is time for that process to shut it needs to release all those\nresources back to the operating system and exit. This process of\nfreeing up all the things that were being used is called \"graceful\nshutdown\" and is really important to get right in systems that start\nand stop processes repeatedly. On Unix systems, the method for\nachieving a graceful shutdown of a process is to send it a signal\n(usually either `SIGINT` or `SIGTERM`).\n\nThe process can then register a handler for this signal which releases\nany resources that it is holding and exits.\n\nThe alternative to a graceful shutdown is a \"forced termination\". This\nis what happens when a process is unable to respond to a interrupt or\ntermination signal. In this case, the process is ended immediately\nwithout the opprotunity to release any of the resources it holds.\n\nOn Unix systems, when you invoke `process.kill()` on a `ChildProcess`\nobject, it sends the `SIGTERM` signal. That way, if the process has a\n`SIGTERM` handler it has an opportunity to perform a graceful\nshutdown.\n\nWindows on the other hand, does not have a method to send signals to a\nprocess, so when you invoke the same `process.kill()` function on\n_that_ platform, what you end up with is a forceful termination\nwithout any cleanup. However, Windows _does_ have a method for\napplications to shutdown gracefully, namely hitting `CTRL-C` on the\nconsole to which the process is attached. And that's what this is all\nabout. In fact, whenever you hit `CTRL-C` on a windows console that is\nrunning a `node` application, `node` will translate that `CTRL-C` into\na `SIGINT` and dispatch any `SIGINT` handlers that it has\nregistered. Since most well-behaved long-running Nodejs processes\nrespond to `SIGINT`, this allows them to shutdown too.\n\nThis module exports a single `ctrlc` function which accepts a process\nid, and sends a `CTRL-C` event to that console.\n\n\u003e Note: This is a no-op on non-windows platforms\n\n## Usage\n\n``` javascript\nimport { ctrlc } from 'ctrlc-windows';\n\nexport function gracefulShutdown(process) {\n  if (process.platform === 'win32') {\n    ctrlc(process.pid);\n  } else {\n    process.kill();\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthefrontside%2Fctrlc-windows","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthefrontside%2Fctrlc-windows","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthefrontside%2Fctrlc-windows/lists"}