---
name: "kvm_getcptime"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/kvm_getcptime"
---

# kvm\_getcptime(3)

fetch global CPU time statistics

## NAME

**kvm\_getcptime** – fetch global CPU time statistics

## LIBRARY

Kernel Data Access Library (libkvm, -lkvm)

## SYNOPSIS

**#include \<sys/param.h\>**

**#include \<sys/resource.h\>**

**#include \<sys/sysctl.h\>**

**#include \<kvm.h\>**

*int*\

**kvm\_getcptime**(*kvm\_t \*kd*, *long \*cp\_time*);

## DESCRIPTION

The **kvm\_getcptime**() function stores the global CPU time statistics from the kernel *kd* in the array of counters pointed to by *cp\_time*. Note that *cp\_time* should point to an array of CPUSTATES long integers. The format of the counters is identical to that output by the *kern.cp\_time* sysctl.

## CACHING

This function caches the nlist values for various kernel variables which it reuses in successive calls. You may call the function with *kd* set to NULL to clear this cache.

## RETURN VALUES

The **kvm\_getcptime** function returns 0 on success and -1 on failure. If an error occurs, then an error message may be retrieved via [kvm\_geterr(3)](/kvm_geterr/3.md).

## SEE ALSO

[kvm(3)](/kvm/3.md)
