{"_id":"@3-/killold","_rev":"3-71e658b83b6960ea947e623af30e3e60","name":"@3-/killold","dist-tags":{"latest":"0.1.3"},"versions":{"0.1.1":{"name":"@3-/killold","version":"0.1.1","keywords":[],"author":{"name":"i18n.site@gmail.com"},"license":"MulanPSL-2.0","_id":"@3-/killold@0.1.1","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/i18n-site/lib/tree/dev/killold","bugs":{"url":"https://github.com/i18n-site/lib/issues"},"dist":{"shasum":"2377dc1f0605145b3e86d82f7750262cc1bea40d","tarball":"https://registry.npmjs.org/@3-/killold/-/killold-0.1.1.tgz","fileCount":3,"integrity":"sha512-1vKBtH1OjktudZztCY7vGBv4wQa03eW/AddxeEe8zOAYmacvJwhrHuIyOJVRD8QGJgoIDEohOR5RU7XuUloRyQ==","signatures":[{"sig":"MEUCICZZL+DtEneN7TpTwu+LF07q4xs6Eqjh4ilywvBgyUDAAiEAtG2UyyVVdS7KlV7LaI1ucOybHKoq/KeMKJa8rmPtZOc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":3190},"type":"module","exports":{".":"./lib.js","./*":"./*"},"gitHead":"e40f66f4aa6ad8eed6f1b47068acc3bdca755ca7","scripts":{},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/i18n-site/lib.git","type":"git"},"_npmVersion":"11.13.0","description":"[English](#en) | [中文](#zh)","directories":{},"_nodeVersion":"26.2.0","dependencies":{"@3-/int":"^0.1.1","@3-/log":"^0.1.9","@3-/read":"^0.1.4","@3-/sleep":"^0.0.4","@3-/write":"^0.0.2"},"_hasShrinkwrap":false,"devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/killold_0.1.1_1780162816343_0.1461165808649476","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@3-/killold","version":"0.1.2","keywords":["pid","kill","lock","process","single-instance"],"author":{"name":"i18n.site@gmail.com"},"license":"MulanPSL-2.0","_id":"@3-/killold@0.1.2","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/i18n-site/lib/tree/dev/killold","bugs":{"url":"https://github.com/i18n-site/lib/issues"},"dist":{"shasum":"18694704eeee40a3ac17c71bd976466264433a84","tarball":"https://registry.npmjs.org/@3-/killold/-/killold-0.1.2.tgz","fileCount":3,"integrity":"sha512-Z6C5Qeadx0cd2TnXjy63wr6NURC1lzCvSKeeJDeQ8JdBB6z5dflE0R9u/KHfOrD9emLQywaKiwNkPEf03r/WaA==","signatures":[{"sig":"MEYCIQDlD9+PKsrmJ4dKBuALiyXg18QSXCRbly8m6DZ606F4VgIhAKm/vqJg3O6d/Y6tvzXN30wGqAggzaMlvWNQFL8W0hNw","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":8922},"type":"module","exports":{".":"./lib.js","./*":"./*"},"gitHead":"33544c536b121e19585acfc5b8f94a7c2d8f4d66","scripts":{},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/i18n-site/lib.git","type":"git"},"_npmVersion":"11.13.0","description":"Kill previous running instances of the script by PID file / 通过 PID 文件清理运行中的旧进程实例","directories":{},"_nodeVersion":"26.2.0","dependencies":{"@3-/int":"^0.1.1","@3-/log":"^0.1.9","@3-/read":"^0.1.4","@3-/sleep":"^0.0.4","@3-/write":"^0.0.2"},"_hasShrinkwrap":false,"devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/killold_0.1.2_1780163351573_0.8950334490069354","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"@3-/killold","version":"0.1.3","description":"Kill previous running instances of the script by PID file / 通过 PID 文件清理运行中的旧进程实例","keywords":["kill","lock","pid","process","single-instance"],"homepage":"https://github.com/i18n-site/lib/tree/dev/killold","license":"MulanPSL-2.0","author":{"name":"i18n.site@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/i18n-site/lib.git"},"type":"module","exports":{".":"./lib.js","./*":"./*"},"scripts":{},"dependencies":{"@3-/int":"^0.1.1","@3-/log":"^0.1.9","@3-/read":"^0.1.4","@3-/sleep":"^0.0.4","@3-/write":"^0.0.2","fkill":"^10.0.3"},"devDependencies":{"knip":"^6.22.0"},"gitHead":"08cbf888b88a3c076394834214d62433cc3ccf83","_id":"@3-/killold@0.1.3","bugs":{"url":"https://github.com/i18n-site/lib/issues"},"_nodeVersion":"26.2.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-acPuDjVnFa+jbL5V/ku925O3qoxahzb9Shrdai/rsv+LcVjL9PLaSIVL3n402gUwLlOaZoNb3/JNZ3vblj4HNQ==","shasum":"4b2d540c55e7b77ae2dff4fbeb41782f5b6df7f0","tarball":"https://registry.npmjs.org/@3-/killold/-/killold-0.1.3.tgz","fileCount":3,"unpackedSize":9606,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCRO5e4yidE2SJnq0/Ug9XlO8Enu0asR7TXIw10LeWCiwIhAPz4fPmjG2jRI/h4HNeKfnzckG14VEAUdhLhRkLvYI4D"}]},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"directories":{},"maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/killold_0.1.3_1782620176059_0.1130966798765991"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-30T17:40:16.148Z","modified":"2026-06-28T04:16:16.314Z","0.1.1":"2026-05-30T17:40:16.508Z","0.1.2":"2026-05-30T17:49:11.706Z","0.1.3":"2026-06-28T04:16:16.195Z"},"bugs":{"url":"https://github.com/i18n-site/lib/issues"},"author":{"name":"i18n.site@gmail.com"},"license":"MulanPSL-2.0","homepage":"https://github.com/i18n-site/lib/tree/dev/killold","keywords":["kill","lock","pid","process","single-instance"],"repository":{"type":"git","url":"git+https://github.com/i18n-site/lib.git"},"description":"Kill previous running instances of the script by PID file / 通过 PID 文件清理运行中的旧进程实例","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"readme":"[English](#en) | [中文](#zh)\n\n---\n\n<a id=\"en\"></a>\n# @3-/killold : Terminate running old instances of the script\n\n- [Introduction](#introduction)\n- [Usage](#usage)\n- [Features](#features)\n- [Design](#design)\n- [Stack](#stack)\n- [Directory](#directory)\n- [API](#api)\n- [History](#history)\n\n## Introduction\n\n`@3-/killold` ensures single-instance execution for scripts. It detects and terminates previously running instances of the same script via PID lock files generated in the system temporary directory.\n\n## Usage\n\n```javascript\nimport killold from \"@3-/killold\";\n\n// Terminate old instances and lock current script\nawait killold();\n```\n\nIf no path is specified, the runner script path (`process.argv[1]`) is locked by default.\n\n## Features\n\n- Detects and terminates older running instances of the same script.\n- Validates process existence and control permissions safely using signal 0.\n- Removes PID lock files automatically on normal exit, `SIGINT`, or `SIGTERM`.\n- Supports customizing the target path for lock generation.\n\n## Design\n\nThe module executes the following process flow:\n\n```mermaid\ngraph TD\n  A[Start killold] --> B{Path specified?}\n  B -->|Yes| C[Resolve path]\n  B -->|No| D[Resolve process.argv 1]\n  C --> E[Generate PID file path in temp directory]\n  D --> E\n  E --> F{PID file exists?}\n  F -->|Yes| G[Read PID from file]\n  G --> H{Process running and not self?}\n  H -->|Yes| I[Send SIGKILL 9 and sleep 1s]\n  I --> H\n  H -->|No| J[Write current PID to file]\n  F -->|No| J\n  J --> K[Register exit handlers to delete file]\n  K --> L[Finish]\n```\n\n## Stack\n\n- Runtime API: Node.js / Bun process and filesystem APIs.\n- Dependencies:\n  - `@3-/int`\n  - `@3-/log`\n  - `@3-/read`\n  - `@3-/sleep`\n  - `@3-/write`\n\n## Directory\n\n```\n.\n├── src\n│   └── lib.js          # Core implementation\n├── tests               # Test directory\n├── readme\n│   ├── en.md           # English documentation\n│   └── zh.md           # Chinese documentation\n└── package.json        # Project metadata\n```\n\n## API\n\n### default export async (path?: string): Promise&lt;void&gt;\n\n- **Parameters**:\n  - `path`: Target file path for locking. Defaults to `process.argv[1]`.\n- **Returns**:\n  - `Promise<void>`: Resolves when old instances are terminated and current PID is written.\n\n## History\n\nIn early Unix editions around 1973, the `kill` command was introduced solely to force termination of processes by the superuser. As Unix evolved, `kill` became a general-purpose tool to send various signals (such as configuration reload signals), yet the name stuck. PID files emerged during the System V init era, providing a lightweight way for startup scripts to locate and control background daemons. This lock file approach remains a standard convention for process isolation.\n\n---\n\n<a id=\"zh\"></a>\n# @3-/killold : 清理当前运行脚本的旧进程实例\n\n- [项目功能介绍](#项目功能介绍)\n- [使用演示](#使用演示)\n- [特性介绍](#特性介绍)\n- [设计思路](#设计思路)\n- [技术堆栈](#技术堆栈)\n- [目录结构](#目录结构)\n- [API 说明](#api-说明)\n- [历史小故事](#历史小故事)\n\n## 项目功能介绍\n\n`@3-/killold` 用于保证脚本单实例运行。本模块通过在系统临时目录中创建以运行文件绝对路径命名的 PID 锁文件，自动检测并强行终止先前启动的同名脚本旧进程。\n\n## 使用演示\n\n```javascript\nimport killold from \"@3-/killold\";\n\n// 清理旧实例并锁定当前脚本\nawait killold();\n```\n\n若调用时不传入参数，则默认锁定并清理当前运行脚本（即 `process.argv[1]`）。\n\n## 特性介绍\n\n- 自动检测并强行终止正在运行的冲突旧实例。\n- 使用信号 0 安全校验进程是否存在及控制权限。\n- 自动注册清理程序，在正常退出、SIGINT 及 SIGTERM 时同步删除锁文件。\n- 支持传入自定义文件路径以生成对应锁文件。\n\n## 设计思路\n\n本模块执行流程如下：\n\n```mermaid\ngraph TD\n  A[开始 killold] --> B{是否指定路径?}\n  B -->|是| C[解析指定路径]\n  B -->|否| D[解析当前运行脚本路径]\n  C --> E[在系统临时目录中生成锁文件路径]\n  D --> E\n  E --> F{锁文件是否存在?}\n  F -->|是| G[读取文件中的旧 PID]\n  G --> H{旧进程是否存在且非当前进程?}\n  H -->|是| I[发送 SIGKILL 9 信号并等待 1 秒]\n  I --> H\n  H -->|否| J[写入当前进程 PID 至锁文件]\n  F -->|否| J\n  J --> K[注册退出监听事件以清除锁文件]\n  K --> L[结束]\n```\n\n## 技术堆栈\n\n- 运行环境 API：Node.js / Bun 进程与文件系统 API。\n- 核心依赖：\n  - `@3-/int`\n  - `@3-/log`\n  - `@3-/read`\n  - `@3-/sleep`\n  - `@3-/write`\n\n## 目录结构\n\n```\n.\n├── src\n│   └── lib.js          # 核心实现逻辑\n├── tests               # 测试目录\n├── readme\n│   ├── en.md           # 英文文档\n│   └── zh.md           # 中文文档\n└── package.json        # 项目元数据与依赖配置\n```\n\n## API 说明\n\n### 默认导出 async (path?: string): Promise&lt;void&gt;\n\n- **参数**：\n  - `path`: 目标定位文件路径，可选，默认值为 `process.argv[1]`。\n- **返回值**：\n  - `Promise<void>`: 旧实例清理完毕且当前进程锁写入完成后 resolve。\n\n## 历史小故事\n\n1973 年，Unix 第三版首次引入 `kill` 命令，最初仅供超级用户强行终止进程。随着系统演进，`kill` 扩展为向进程发送各类信号的通用工具，但该命名一直沿用至今。PID 锁文件起源于 System V 初始化脚本时代，为脚本管理后台服务提供轻量定位手段，至今仍是进程隔离设计中的经典做法。\n\n---\n\n## About\n\nThis project is an open-source component of [i18n.site ⋅ Internationalization Solution](https://i18n.site).\n\n- [i18 : MarkDown Command Line Translation Tool](https://i18n.site/i18)\n\n  The translation perfectly maintains the Markdown format.\n\n  It recognizes file changes and only translates the modified files.\n\n  The translated Markdown content is editable; if you modify the original text and translate it again, manually edited translations will not be overwritten (as long as the original text has not been changed).\n\n- [i18n.site : MarkDown Multi-language Static Site Generator](https://i18n.site/i18n.site)\n\n  Optimized for a better reading experience\n\n## 关于\n\n本项目为 [i18n.site ⋅ 国际化解决方案](https://i18n.site) 的开源组件。\n\n- [i18 : MarkDown命令行翻译工具](https://i18n.site/i18)\n\n  翻译能够完美保持 Markdown 的格式。能识别文件的修改，仅翻译有变动的文件。\n\n  Markdown 翻译内容可编辑；如果你修改原文并再次机器翻译，手动修改过的翻译不会被覆盖（如果这段原文没有被修改）。\n\n- [i18n.site : MarkDown多语言静态站点生成器](https://i18n.site/i18n.site) 为阅读体验而优化。\n","readmeFilename":"README.md"}