Skip to content

Windows: process memory is null/0 when pm2 runs as a service since 7.0.1 - bump pidusage to 4.1.0 #6173

Closed

Description

@industry-capitan

What happens

Since pm2 7.0.1 (pidusage 3.0.2 -> 4.0.1), on Windows pm2 ls shows memory as nullb for every process when the pm2 daemon runs as a Windows service (session 0, no console). pm2 jlist returns monit.memory: null, monitoring shows 0, and max_memory_restart never triggers. With pm2 6.x (pidusage 3.0.2) the same hosts reported memory correctly.

Root cause (pidusage 4.0.1)

  • lib/stats.js probes for wmic with spawn('wmic', function (err) { ... }). Passing a function as args makes Node throw ERR_INVALID_ARG_TYPE synchronously, so the catch branch always switches to the gwmi backend. wmic is never used, even where WMIC.exe exists.
  • The gwmi backend runs powershell gwmi win32_process ... | select ... | format-table and splits rows on whitespace. Without a console, PowerShell formats to a width of 80; a row is ~95 characters, so Format-Table drops the last column (WorkingSetSize) and parseInt(undefined) gives NaN (serialized as null).
  • From an interactive terminal (width 120) the same code works, which is why this mostly hits service installs.

Fix available upstream

pidusage 4.1.0 (2026-10-13, soyuka/pidusage#195) detects WMIC.exe once with fs.existsSync and uses wmic when it is present. index.js and the API are unchanged; pm2 only calls pidusage(pids, cb) in lib/God/ActionMethods.js.

We replaced node_modules/pm2/node_modules/pidusage with 4.1.0 on Windows Server 2016 hosts running pm2 7.0.4 as a service: memory is reported again, max_memory_restart works, and each poll is one wmic call instead of two powershell.exe launches (~0.3 s instead of ~0.9 s per poll in our measurement).

pm2 7.0.4 pins "pidusage": "4.0.1" exactly, so users cannot pick up the fix without patching the installed package. Could the dependency be bumped to ~4.1.0?

Environment

  • pm2 7.0.4, Node.js 24.22.0
  • Windows Server 2016, pm2 daemon started by a Windows service wrapper (LocalSystem / NetworkService)

Possibly related Windows memory / pidusage reports: #5853, #5824, #6074, #5940.

Activity

  1. added a commit that references this issue on Oct 22, 2026
  2. Unitech commented on Nov 3, 2026

    @Unitech
    Owner

    Fixed on pm2@7.1.1

    $ npm install pm2@latest -g
    $ pm2 update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions