{"id":13465001,"url":"https://github.com/soyuka/pidusage","last_synced_at":"2025-05-14T19:09:58.782Z","repository":{"id":16785496,"uuid":"19543900","full_name":"soyuka/pidusage","owner":"soyuka","description":"Cross-platform process cpu % and memory usage of a PID","archived":false,"fork":false,"pushed_at":"2025-04-26T19:19:02.000Z","size":799,"stargazers_count":524,"open_issues_count":17,"forks_count":56,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-26T20:24:28.692Z","etag":null,"topics":["cpu","hacktoberfest","memory","percent","processor","usage"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soyuka.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-05-07T17:36:47.000Z","updated_at":"2025-04-26T19:19:06.000Z","dependencies_parsed_at":"2024-06-18T11:22:41.675Z","dependency_job_id":"8a16e6c4-f33b-4b71-95d6-ace2fab36d29","html_url":"https://github.com/soyuka/pidusage","commit_stats":{"total_commits":217,"total_committers":22,"mean_commits":9.863636363636363,"dds":0.6774193548387097,"last_synced_commit":"61480f745a3f4dd780118b6aabf00bc1f58d5d87"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soyuka%2Fpidusage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soyuka%2Fpidusage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soyuka%2Fpidusage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soyuka%2Fpidusage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soyuka","download_url":"https://codeload.github.com/soyuka/pidusage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254209859,"owners_count":22032897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpu","hacktoberfest","memory","percent","processor","usage"],"created_at":"2024-07-31T14:00:54.714Z","updated_at":"2025-05-14T19:09:56.198Z","avatar_url":"https://github.com/soyuka.png","language":"JavaScript","readme":"# pidusage\n\n[![Lint](https://github.com/soyuka/pidusage/workflows/lint/badge.svg?branch=main)](https://github.com/soyuka/pidusage/actions?query=workflow:lint+branch:main)\n[![MacOS](https://github.com/soyuka/pidusage/workflows/test-macos/badge.svg?branch=main)](https://github.com/soyuka/pidusage/actions?query=workflow:test-macos+branch:main)\n[![Ubuntu](https://github.com/soyuka/pidusage/workflows/linux/badge.svg?branch=main)](https://github.com/soyuka/pidusage/actions?query=workflow:linux+branch:main)\n[![Windows](https://github.com/soyuka/pidusage/workflows/test-windows/badge.svg?branch=main)](https://github.com/soyuka/pidusage/actions?query=workflow:test-windows+branch:main)\n[![Alpine](https://github.com/soyuka/pidusage/workflows/test-alpine/badge.svg?branch=main)](https://github.com/soyuka/pidusage/actions?query=workflow:test-alpine+branch:main)\n[![Code coverage](https://img.shields.io/codecov/c/github/soyuka/pidusage/master.svg)](https://codecov.io/gh/soyuka/pidusage)\n[![npm version](https://img.shields.io/npm/v/pidusage.svg)](https://www.npmjs.com/package/pidusage)\n[![license](https://img.shields.io/github/license/soyuka/pidusage.svg)](https://github.com/soyuka/pidusage/tree/master/license)\n\nCross-platform process cpu % and memory usage of a PID.\n\n## Synopsis\n\nIdeas from https://github.com/arunoda/node-usage but with no C-bindings.\n\nPlease note that if you need to check a Node.JS script process cpu and memory usage, you can use [`process.cpuUsage`][node:cpuUsage] and [`process.memoryUsage`][node:memUsage] since node v6.1.0. This script remain useful when you have no control over the remote script, or if the process is not a Node.JS process.\n\n\n## Usage\n\n```js\nvar pidusage = require('pidusage')\n\npidusage(process.pid, function (err, stats) {\n  console.log(stats)\n  // =\u003e {\n  //   cpu: 10.0,            // percentage (from 0 to 100*vcore)\n  //   memory: 357306368,    // bytes\n  //   ppid: 312,            // PPID\n  //   pid: 727,             // PID\n  //   ctime: 867000,        // ms user + system time\n  //   elapsed: 6650000,     // ms since the start of the process\n  //   timestamp: 864000000  // ms since epoch\n  // }\n  cb()\n})\n\n// It supports also multiple pids\npidusage([727, 1234], function (err, stats) {\n  console.log(stats)\n  // =\u003e {\n  //   727: {\n  //     cpu: 10.0,            // percentage (from 0 to 100*vcore)\n  //     memory: 357306368,    // bytes\n  //     ppid: 312,            // PPID\n  //     pid: 727,             // PID\n  //     ctime: 867000,        // ms user + system time\n  //     elapsed: 6650000,     // ms since the start of the process\n  //     timestamp: 864000000  // ms since epoch\n  //   },\n  //   1234: {\n  //     cpu: 0.1,             // percentage (from 0 to 100*vcore)\n  //     memory: 3846144,      // bytes\n  //     ppid: 727,            // PPID\n  //     pid: 1234,            // PID\n  //     ctime: 0,             // ms user + system time\n  //     elapsed: 20000,       // ms since the start of the process\n  //     timestamp: 864000000  // ms since epoch\n  //   }\n  // }\n})\n\n// If no callback is given it returns a promise instead\nconst stats = await pidusage(process.pid)\nconsole.log(stats)\n// =\u003e {\n//   cpu: 10.0,            // percentage (from 0 to 100*vcore)\n//   memory: 357306368,    // bytes\n//   ppid: 312,            // PPID\n//   pid: 727,             // PID\n//   ctime: 867000,        // ms user + system time\n//   elapsed: 6650000,     // ms since the start of the process\n//   timestamp: 864000000  // ms since epoch\n// }\n\n// Avoid using setInterval as they could overlap with asynchronous processing\nfunction compute(cb) {\n  pidusage(process.pid, function (err, stats) {\n    console.log(stats)\n    // =\u003e {\n    //   cpu: 10.0,            // percentage (from 0 to 100*vcore)\n    //   memory: 357306368,    // bytes\n    //   ppid: 312,            // PPID\n    //   pid: 727,             // PID\n    //   ctime: 867000,        // ms user + system time\n    //   elapsed: 6650000,     // ms since the start of the process\n    //   timestamp: 864000000  // ms since epoch\n    // }\n    cb()\n  })\n}\n\nfunction interval(time) {\n  setTimeout(function() {\n    compute(function() {\n      interval(time)\n    })\n  }, time)\n}\n\n// Compute statistics every second:\ninterval(1000)\n\n// Above example using async/await\nconst compute = async () =\u003e {\n  const stats = await pidusage(process.pid)\n  // do something\n}\n\n// Compute statistics every second:\nconst interval = async (time) =\u003e {\n  setTimeout(async () =\u003e {\n    await compute()\n    interval(time)\n  }, time)\n}\n\ninterval(1000)\n```\n\n## Compatibility\n\n| Property | Linux | FreeBSD | NetBSD | SunOS | macOS | Win | AIX | Alpine\n| ---         | --- | --- | --- | --- | --- | --- | --- | --- |\n| `cpu`       | ✅ | ❓ | ❓ | ❓ | ✅ | ℹ️ | ❓ | ✅ |\n| `memory`    | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |\n| `pid`       | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |\n| `ctime`     | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |\n| `elapsed`   | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |\n| `timestamp` | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |\n\n✅ = Working\nℹ️ = Not Accurate\n❓ = Should Work\n❌ = Not Working\n\nPlease if your platform is not supported or if you have reported wrong readings\n[file an issue][new issue].\n\nBy default, pidusage will use `procfile` parsing on most unix systems. If you want to use `ps` instead use the `usePs` option:\n\n```\npidusage(pid, {usePs: true})\n```\n\n## API\n\n\u003ca name=\"pidusage\"\u003e\u003c/a\u003e\n\n### pidusage(pids, [options = {}], [callback]) ⇒ \u003ccode\u003e[Promise.\u0026lt;Object\u0026gt;]\u003c/code\u003e\nGet pid informations.\n\n**Kind**: global function\n**Returns**: \u003ccode\u003ePromise.\u0026lt;Object\u0026gt;\u003c/code\u003e - Only when the callback is not provided.\n**Access**: public\n\n| Param | Type | Description |\n| --- | --- | --- |\n| pids | \u003ccode\u003eNumber\u003c/code\u003e \\| \u003ccode\u003eArray.\u0026lt;Number\u0026gt;\u003c/code\u003e \\| \u003ccode\u003eString\u003c/code\u003e \\| \u003ccode\u003eArray.\u0026lt;String\u0026gt;\u003c/code\u003e | A pid or a list of pids. |\n| [options] | \u003ccode\u003eobject\u003c/code\u003e | Options object. See the table below. |\n| [callback] | \u003ccode\u003efunction\u003c/code\u003e | Called when the statistics are ready. If not provided a promise is returned instead. |\n\n### options\n\nSetting the options programatically will override environment variables\n\n| Param | Type | Environment variable | Default | Description |\n| --- | --- | --- | --- | --- |\n| [usePs] | \u003ccode\u003eboolean\u003c/code\u003e | `PIDUSAGE_USE_PS`| `false` | When true uses `ps` instead of proc files to fetch process information |\n| [maxage] | \u003ccode\u003enumber\u003c/code\u003e | `PIDUSAGE_MAXAGE`| `60000` | Max age of a process on history. |\n\n`PIDUSAGE_SILENT=1` can be used to remove every console message triggered by pidusage.\n\n### pidusage.clear()\n\nIf needed this function can be used to delete all in-memory metrics and clear the event loop. This is not necessary before exiting as the interval we're registring does not hold up the event loop.\n\n## Related\n- [pidusage-tree][gh:pidusage-tree] -\nCompute a pidusage tree\n\n## Authors\n- **Antoine Bluchet** - [soyuka][github:soyuka]\n- **Simone Primarosa** - [simonepri][github:simonepri]\n\nSee also the list of [contributors][contributors] who participated in this project.\n\n## License\nThis project is licensed under the MIT License - see the [LICENSE][license] file for details.\n\n\u003c!-- Links --\u003e\n[new issue]: https://github.com/soyuka/pidusage/issues/new\n[license]: https://github.com/soyuka/pidusage/tree/master/LICENSE\n[contributors]: https://github.com/soyuka/pidusage/contributors\n\n[github:soyuka]: https://github.com/soyuka\n[github:simonepri]: https://github.com/simonepri\n\n[gh:pidusage-tree]: https://github.com/soyuka/pidusage-tree\n\n[node:cpuUsage]: https://nodejs.org/api/process.html#process_process_cpuusage_previousvalue\n[node:memUsage]: https://nodejs.org/api/process.html#process_process_memoryusage\n","funding_links":[],"categories":["Repository","hacktoberfest","JavaScript"],"sub_categories":["Performance Profiling/Analysis"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoyuka%2Fpidusage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoyuka%2Fpidusage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoyuka%2Fpidusage/lists"}