博客
关于我
《Linux系统调用:clock_getcpuclockid,pthread_getcpuclockid》
阅读量:234 次
发布时间:2019-03-01

本文共 634 字,大约阅读时间需要 2 分钟。

一、介绍

这组函数用于获取指定进程或线程的CPU时钟ID值,分别是clock_getcpuclockidpthread_getcpuclockid。前者用于获取进程的CPU时钟ID,后者则用于获取线程的CPU时钟ID。在编译时需要加上相应的标志选项,-lrt用于clock_getcpuclockid-pthread用于pthread_getcpuclockid

尽管这些函数的精度可以达到纳秒级别,但实际系统的精度可能因实现而异。因此,建议使用clock_getres来获取系统时钟的精度。返回的错误信息请参考 errno 错误值的相关文档。

二、接口函数

以下是相关接口的实现和说明:

#include 
int clock_getcpuclockid(pid_t pid, clockid_t *clock_id);

参数

  • thread:进程ID
  • clock_id:返回的时钟ID值

返回值

成功返回0,错误返回非零的errno值

#include 
#include
int pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id);

参数

  • thread:线程ID
  • clock_id:返回的时钟ID值

返回值

成功返回0,错误返回非零的errno值
注意:如果系统不支持每线程CPU时钟ID,可能会返回ENOENT错误。

转载地址:http://xhkt.baihongyu.com/

你可能感兴趣的文章
ProjectEuler 2
查看>>
projection介绍及EPSG:4326和EPSG:3857的投射转换
查看>>
project打开文件时,显示无法识别此文件格式?
查看>>
Prometheus + Grafana on Kubernetes部署
查看>>
prometheus + grafana进行服务器资源监控
查看>>
Prometheus Alertmanager 告警配置详解
查看>>
Prometheus Grafana 展示平台
查看>>
Prometheus pushgateway使用详解
查看>>
Prometheus 云原生 - Prometheus 数据模型、Metrics 指标类型、Exporter 相关
查看>>
Prometheus 云原生 - 基于 file_sd、http_sd 实现 Service Discovery
查看>>
Prometheus 云原生 - 微服务监控报警系统 (Promethus、Grafana、Node_Exporter)部署、简单使用
查看>>
Prometheus 云原生 - 监控 Linux、MySQL、Redis、RabbitMQ、Docker、SpringBoot 3.x
查看>>
Prometheus 介绍
查看>>
Prometheus 安全配置详解
查看>>
prometheus 安装node_exporter, node_exporter 安装最新版 普罗米修思安装监控服务器client
查看>>
Prometheus 安装部署实战
查看>>
prometheus 持久化存储方案
查看>>
Prometheus 监控系统企业级实战
查看>>
Prometheus 监控系统简介
查看>>
Prometheus 配置详解
查看>>