-
-
Notifications
You must be signed in to change notification settings - Fork 34k
util: process signal to exit code utility #60963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
util: process signal to exit code utility #60963
Conversation
Add convertProcessSignalToExitCode() to convert signal names to POSIX exit codes (128 + signal number). Exposed in public util API. Refs: nodejs#60720
Document util.convertProcessSignalToExitCode() in child_process module to help users convert signal names to POSIX exit codes when a child process is terminated by a signal. Refs: nodejs#60285
doc/api/child_process.md
Outdated
| console.log(`signal ${signal}, POSIX exit code: ${exitCode}`); | ||
|
|
||
| // signal SIGTERM, POSIX exit code: 143 | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove the code samples and move the text to the bottom of the section – there's very little reason why somebody would want to do this, while information such as that stdio streams may still be open is much more directly relevant to what this event does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
doc/api/child_process.md
Outdated
| If the child process is still running, the field will be `null`. | ||
| When the child process is terminated by a signal, `subprocess.exitCode` will be | ||
| `null`. To get the corresponding POSIX exit code, use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the really important thing we should mention is that subprocess.signalCode will be set, and we should link to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| * Type: {string|null} | ||
| The `subprocess.signalCode` property indicates the signal received by | ||
| the child process if any, else `null`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might also be worth linking back to .exitCode from here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #60963 +/- ##
==========================================
+ Coverage 88.53% 88.54% +0.01%
==========================================
Files 703 703
Lines 208413 208448 +35
Branches 40191 40195 +4
==========================================
+ Hits 184521 184575 +54
+ Misses 15902 15884 -18
+ Partials 7990 7989 -1
🚀 New features to boost your workflow:
|
Description
Adds
util.convertProcessSignalToExitCode()utility function to convert signal names (e.g.,SIGTERM,SIGKILL) to their corresponding POSIX exit codes.When a child process is terminated by a signal, the
codeparameter in the'exit'and'close'events isnull. This utility allows users to convert thesignalparameter to the POSIX standard exit code.Example
Note: While Windows doesn't natively support POSIX signals, Node.js provides a cross-platform abstraction that emulates signal behavior. This allows
convertProcessSignalToExitCode()to work consistently across all platforms, returning the same POSIX exit codes on both Unix-like systems and Windows.Refs