Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. CPU usage per process

CPU usage per process

Scheduled Pinned Locked Moved Java
json
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kartikdasani
    wrote on last edited by
    #1

    Is there a way to list the CPU usage per process of all the processes that are currently running in the system. What I mean is CPU % usage as is shown in the Taskmanager. I have tried a few API like sigar and JavaSysMon but am not able to get accurate values of the %'s.

    L J 2 Replies Last reply
    0
    • K kartikdasani

      Is there a way to list the CPU usage per process of all the processes that are currently running in the system. What I mean is CPU % usage as is shown in the Taskmanager. I have tried a few API like sigar and JavaSysMon but am not able to get accurate values of the %'s.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I would guess that the only way to get reasonable data if the JavaSysMon() method does not do it, is to use the native process and thread functions[^], using C/C++. This would mean you will have to write JNI[^] or JNA[^] code to act as the interface between C++ and Java.

      Unrequited desire is character building. OriginalGriff

      1 Reply Last reply
      0
      • K kartikdasani

        Is there a way to list the CPU usage per process of all the processes that are currently running in the system. What I mean is CPU % usage as is shown in the Taskmanager. I have tried a few API like sigar and JavaSysMon but am not able to get accurate values of the %'s.

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        Steps. 1. Find or create a command line tool that does that. 2. Use java Runtime.exec() to run it and get the results.

        D 1 Reply Last reply
        0
        • J jschell

          Steps. 1. Find or create a command line tool that does that. 2. Use java Runtime.exec() to run it and get the results.

          D Offline
          D Offline
          David Skelly
          wrote on last edited by
          #4

          These days you should probably prefer ProcessBuilder to Runtime for executing external processes. ProcessBuilder does everything Runtime.exec does and more, so it's probably worth getting into the habit of using it. After all it has been around since 1.5 which came in years ago.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups