Skip to content

Conversation

@ErickWendel
Copy link
Member

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 code parameter in the 'exit' and 'close' events is null. This utility allows users to convert the signal parameter to the POSIX standard exit code.

Example

import { spawn } from 'node:child_process';
import { once } from 'node:events';
import { convertProcessSignalToExitCode } from 'node:util';

const ls = spawn('ls', ['-lh', '/usr']);

ls.kill();

const [code, signal] = await once(ls, 'exit');
const exitCode = convertProcessSignalToExitCode(signal);
console.log(`signal ${signal}, POSIX exit code: ${exitCode}`);

// signal SIGTERM, POSIX exit code: 143

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

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
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Dec 5, 2025
@RafaelGSS RafaelGSS added semver-minor PRs that contain new features and should be released in the next minor version. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Dec 5, 2025
@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.54%. Comparing base (cbe0233) to head (ccf99c9).
⚠️ Report is 16 commits behind head on main.

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     
Files with missing lines Coverage Δ
lib/internal/util.js 96.81% <100.00%> (+0.43%) ⬆️
lib/util.js 97.97% <100.00%> (+<0.01%) ⬆️

... and 43 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@addaleax addaleax added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Dec 9, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 9, 2025
@nodejs-github-bot
Copy link
Collaborator

@aduh95
Copy link
Contributor

aduh95 commented Dec 9, 2025

Seemingly related failure on Windows:

---
duration_ms: 175.001
exitcode: 1
severity: fail
stack: |-
  node:internal/modules/run_main:107
      triggerUncaughtException(
      ^

  AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

  150 !== 134

      at file:///c:/workspace/node-test-binary-windows-js-suites/node/test/parallel/test-util-convert-signal-to-exit-code.mjs:20:10
      at ModuleJob.run (node:internal/modules/esm/module_job:430:25)
      at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:654:26)
      at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: 150,
    expected: 134,
    operator: 'strictEqual',
    diff: 'simple'
  }

  Node.js v26.0.0-pre

@nodejs-github-bot
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants