Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS: get information on a process from the process ID

I am writing a small NodeJS service that I want to be able to monitor a process given the PID of that process. I want to be able to gather the following info about the process:

  • Start time
  • CPU time used
  • Memory usage

All processes that I will be monitoring will have been started using the child_process exec (or spawn) function, so I can get the PID from there. Technically, I could record the start time when the process is spawned, but I think this wouldn't be all that accurate?

What would be the best way to get all the above information? It would be good to get and end time when the process exited as well.

like image 952
David Brown Avatar asked Sep 01 '25 06:09

David Brown


1 Answers

pidusage is one great module which can get you all details (like process cpu % and memory usage of a PID) that you need pertaining to a pid upon supplying the same as an argument.

Another good thing is, this library can run on any platform.

Hope this helps!

like image 125
David R Avatar answered Sep 02 '25 20:09

David R