市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
5.7 KiB

  1. [![Node](https://img.shields.io/badge/-Node.js-808080?logo=node.js&colorA=404040&logoColor=66cc33)](https://www.npmjs.com/package/human-signals)
  2. [![TypeScript](https://img.shields.io/badge/-Typed-808080?logo=typescript&colorA=404040&logoColor=0096ff)](/src/main.d.ts)
  3. [![Codecov](https://img.shields.io/badge/-Tested%20100%25-808080?logo=codecov&colorA=404040)](https://codecov.io/gh/ehmicky/human-signals)
  4. [![Mastodon](https://img.shields.io/badge/-Mastodon-808080.svg?logo=mastodon&colorA=404040&logoColor=9590F9)](https://fosstodon.org/@ehmicky)
  5. [![Medium](https://img.shields.io/badge/-Medium-808080.svg?logo=medium&colorA=404040)](https://medium.com/@ehmicky)
  6. Human-friendly process signals.
  7. This is a map of known process signals with some information about each signal.
  8. Unlike
  9. [`os.constants.signals`](https://nodejs.org/api/os.html#os_signal_constants)
  10. this includes:
  11. - human-friendly [descriptions](#description)
  12. - [default actions](#action), including whether they [can be prevented](#forced)
  13. - whether the signal is [supported](#supported) by the current OS
  14. # Example
  15. ```js
  16. import { signalsByName, signalsByNumber } from 'human-signals'
  17. console.log(signalsByName.SIGINT)
  18. // {
  19. // name: 'SIGINT',
  20. // number: 2,
  21. // description: 'User interruption with CTRL-C',
  22. // supported: true,
  23. // action: 'terminate',
  24. // forced: false,
  25. // standard: 'ansi'
  26. // }
  27. console.log(signalsByNumber[8])
  28. // {
  29. // name: 'SIGFPE',
  30. // number: 8,
  31. // description: 'Floating point arithmetic error',
  32. // supported: true,
  33. // action: 'core',
  34. // forced: false,
  35. // standard: 'ansi'
  36. // }
  37. ```
  38. # Install
  39. ```bash
  40. npm install human-signals
  41. ```
  42. This package works in Node.js >=18.18.0.
  43. This is an ES module. It must be loaded using
  44. [an `import` or `import()` statement](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c),
  45. not `require()`. If TypeScript is used, it must be configured to
  46. [output ES modules](https://www.typescriptlang.org/docs/handbook/esm-node.html),
  47. not CommonJS.
  48. # Usage
  49. ## signalsByName
  50. _Type_: `object`
  51. Object whose keys are signal [names](#name) and values are
  52. [signal objects](#signal).
  53. ## signalsByNumber
  54. _Type_: `object`
  55. Object whose keys are signal [numbers](#number) and values are
  56. [signal objects](#signal).
  57. ## signal
  58. _Type_: `object`
  59. Signal object with the following properties.
  60. ### name
  61. _Type_: `string`
  62. Standard name of the signal, for example `'SIGINT'`.
  63. ### number
  64. _Type_: `number`
  65. Code number of the signal, for example `2`. While most `number` are
  66. cross-platform, some are different between different OS.
  67. ### description
  68. _Type_: `string`
  69. Human-friendly description for the signal, for example
  70. `'User interruption with CTRL-C'`.
  71. ### supported
  72. _Type_: `boolean`
  73. Whether the current OS can handle this signal in Node.js using
  74. [`process.on(name, handler)`](https://nodejs.org/api/process.html#process_signal_events).
  75. The list of supported signals
  76. [is OS-specific](https://github.com/ehmicky/cross-platform-node-guide/blob/main/docs/6_networking_ipc/signals.md#cross-platform-signals).
  77. ### action
  78. _Type_: `string`\
  79. _Enum_: `'terminate'`, `'core'`, `'ignore'`, `'pause'`, `'unpause'`
  80. What is the default action for this signal when it is not handled.
  81. ### forced
  82. _Type_: `boolean`
  83. Whether the signal's default action cannot be prevented. This is `true` for
  84. `SIGTERM`, `SIGKILL` and `SIGSTOP`.
  85. ### standard
  86. _Type_: `string`\
  87. _Enum_: `'ansi'`, `'posix'`, `'bsd'`, `'systemv'`, `'other'`
  88. Which standard defined that signal.
  89. # Support
  90. For any question, _don't hesitate_ to [submit an issue on GitHub](../../issues).
  91. Everyone is welcome regardless of personal background. We enforce a
  92. [Code of conduct](CODE_OF_CONDUCT.md) in order to promote a positive and
  93. inclusive environment.
  94. # Contributing
  95. This project was made with ❤️. The simplest way to give back is by starring and
  96. sharing it online.
  97. If the documentation is unclear or has a typo, please click on the page's `Edit`
  98. button (pencil icon) and suggest a correction.
  99. If you would like to help us fix a bug or add a new feature, please check our
  100. [guidelines](CONTRIBUTING.md). Pull requests are welcome!
  101. Thanks go to our wonderful contributors:
  102. <!-- ALL-CONTRIBUTORS-LIST:START -->
  103. <!-- prettier-ignore-start -->
  104. <!-- markdownlint-disable -->
  105. <table>
  106. <tbody>
  107. <tr>
  108. <td align="center" valign="top" width="14.28%"><a href="https://fosstodon.org/@ehmicky"><img src="https://avatars2.githubusercontent.com/u/8136211?v=4?s=100" width="100px;" alt="ehmicky"/><br /><sub><b>ehmicky</b></sub></a><br /><a href="https://github.com/ehmicky/human-signals/commits?author=ehmicky" title="Code">💻</a> <a href="#design-ehmicky" title="Design">🎨</a> <a href="#ideas-ehmicky" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ehmicky/human-signals/commits?author=ehmicky" title="Documentation">📖</a></td>
  109. <td align="center" valign="top" width="14.28%"><a href="http://www.electrovir.com"><img src="https://avatars0.githubusercontent.com/u/1205860?v=4?s=100" width="100px;" alt="electrovir"/><br /><sub><b>electrovir</b></sub></a><br /><a href="https://github.com/ehmicky/human-signals/commits?author=electrovir" title="Code">💻</a></td>
  110. <td align="center" valign="top" width="14.28%"><a href="https://fzy.se"><img src="https://avatars.githubusercontent.com/u/2656517?v=4?s=100" width="100px;" alt="Felix Zedén Yverås"/><br /><sub><b>Felix Zedén Yverås</b></sub></a><br /><a href="https://github.com/ehmicky/human-signals/commits?author=FelixZY" title="Code">💻</a> <a href="https://github.com/ehmicky/human-signals/commits?author=FelixZY" title="Tests">⚠️</a></td>
  111. </tr>
  112. </tbody>
  113. </table>
  114. <!-- markdownlint-restore -->
  115. <!-- prettier-ignore-end -->
  116. <!-- ALL-CONTRIBUTORS-LIST:END -->