Solved

CPU usage sys-call

Posted on 2001-07-16
1
326 Views
Last Modified: 2010-04-22
Hi

I want to know the CPU usage from a program in C. Is there a sys-call ???

Thanks,

Liron
0
Comment
Question by:lirong
1 Comment
 

Accepted Solution

by:
PaulSmirnoff earned 50 total points
Comment Utility
no syscalls, just access to /dev/kmem

man kvm_read

try to look how it is done in vmstat.c

name is '_cp_time'

--- cut
void
kread(nlx, addr, size)
        int nlx;
        void *addr;
        size_t size;
{
        char *sym;  
           
        if (namelist[nlx].n_type == 0 || namelist[nlx].n_value == 0) {
                sym = namelist[nlx].n_name;
                if (*sym == '_')
                        ++sym;
                errx(1, "symbol %s not defined", sym);
        }
        if (kvm_read(kd, namelist[nlx].n_value, addr, size) != size) {
                sym = namelist[nlx].n_name;
                if (*sym == '_')
                        ++sym;
                errx(1, "%s: %s", sym, kvm_geterr(kd));
        }
}
--- cut

Paul
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now