Solved

CPU usage sys-call

Posted on 2001-07-16
1
329 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
ID: 6285907
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

772 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