Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pidusage-fork

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pidusage-fork

Process cpu % and memory use of a PID

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

pidusage

Build Status Build status

Process cpu % and memory use of a PID

Ideas from https://github.com/arunoda/node-usage/ but with no C-bindings

API

var pusage = require('pidusage')

pusage.stat(process.pid, function(err, stat) {

	expect(err).to.be.null
	expect(stat).to.be.an('object')
	expect(stat).to.have.property('cpu')
	expect(stat).to.have.property('memory')

	console.log('Pcpu: %s', stat.cpu)
	console.log('Mem: %s', stat.memory) //those are bytes

})

// Unmonitor process
pusage.unmonitor(18902);

What do this script do?

A check on the os.platform is done to determine the method to use.

Linux

We use /proc/{pid}/stat in addition to the the PAGE_SIZE and the CLK_TCK direclty from getconf() command. Uptime comes from proc/uptime file because it's more accurate than the nodejs os.uptime().

On darwin, freebsd, solaris (tested on 10/11)

We use a fallback with the ps -o pcpu,rss -p PID command to get the same informations.

On AIX

AIX is tricky because I have no AIX test environement, at the moment we use: ps -o pcpu,rssize -p PID but /proc results should be more accurate! If you're familiar with the AIX environment and now how to get the same results as we've got with Linux systems, please help. #4

Windows

Windows is really tricky, atm it uses the wmic.exe, feel free to share ideas on how to improve this.

Licence

MIT

Keywords

FAQs

Package last updated on 25 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc