From: Joe Van Dyk Date: 2006-01-11T06:31:51+09:00 Subject: Finding CPU% of a linux task Hi, I'm writing a small Ruby module that can find how much cpu percentage a given task is using. I'm doing it by getting the process id of the task that I care about, going into proc, checking the stat file for the process (which contains how many jiffies the task has consumed) and averaging the change of that over time to get a running percentage. However, that doesn't capture threads or forked processes. If a program starts a couple threads (or forks a child process), I then have to figure out the cpu percentage of each of the child threads (and their childs and their child's childs, and so on) and add them together to get a total for the process. I'm struggling to come up with an elegant way to solve this problem. Any ideas? Thanks, Joe