KDK_RTI_GET_CPU_CURRENT_USAGE(3)

📦 version 3.0.1.4, in arch rolling, ubuntu resolute, ubuntu stonking

👑 KDK_RTI_GET_CPU_CURRENT_USAGE(3) 👑

okay bestie, sit down, hydrate, and let me tell you about this lil guy 💖 it lives in the Library Functions Manual (that's section 3, the "functions" girlies, iykyk), and it is literally the one job you need when you wanna know how hard your CPU is sweating right this very second. no cap.


✨ NAME ✨

  • kdk_rti_get_cpu_current_usage — 获取CPU瞬时使用率

🦋 SYNOPSIS 🦋

the way you gotta summon it:

#include <libkyrtinfo.h>

extern float kdk_rti_get_cpu_current_usage();

Link with -lkyrtinfo.
🫶 friendly reminder bestie: that last line means you gotta link with -lkyrtinfo or the linker will simply not know her. tragic. don't do that.

🌸 Detailed Description 🌸

so the entire main character mission of this interface? obtain the instantaneous CPU usage rate. that's it. that's the whole vibe. she walks in, she grabs the current CPU usage, she leaves. no drama, no side quests, just a little number about how busy your processor is right now. obsessed. 💅


⭐ RETURN VALUE ⭐

  • on success — she hands you the instantaneous CPU usage rate, and it's a float. slay. ✨
  • on error — you get 0. just a flat zero. that's the whole thing. 💀

🎀 EXAMPLES 🎀

here's a whole lil program showing her off (and her friends too, because they all roll together):

#include "libkyrtinfo.h"
#include <stdio.h>

int main()
{
    printf("内存总大小:%lu KiB0, kdk_rti_get_mem_res_total_KiB());
    printf("当前已用内存:%lu KiB,%f0, kdk_rti_get_mem_res_usage_KiB(), kdk_rti_get_mem_res_usage_percent());
    printf("当前空闲内存:%lu KiB0, kdk_rti_get_mem_res_free_KiB());
    printf("可用内存大小:%lu KiB0, kdk_rti_get_mem_res_available_KiB());
    printf("应用总申请虚拟内存大小:%lu KiB0, kdk_rti_get_mem_virt_alloc_KiB());
    printf("交换分区总量:%lu KiB0, kdk_rti_get_mem_swap_total_KiB());
    printf("交换分区已用量:%lu KiB, %f0, kdk_rti_get_mem_swap_usage_KiB(), kdk_rti_get_mem_swap_usage_percent());
    printf("交换分区剩余大小:%lu KiB0, kdk_rti_get_mem_swap_free_KiB());
    printf("当前CPU使用率:%f0, kdk_rti_get_cpu_current_usage());
    unsigned int day, hour, min, sec;
    kdk_rti_get_uptime(&day, &hour, &min, &sec);
    printf("开机时长:%u天%u小时%u分钟%u秒0, day, hour, min, sec);
    return 0;
}

see how kdk_rti_get_cpu_current_usage() is just chilling in there with the memory girlies and kdk_rti_get_uptime()? that's the squad. 🫶


🌈 CONFORMING TO 🌈

  • these functions are as per the withdrawn POSIX.1e draft specification. yes bestie, withdrawn. she's vintage. iconic but no longer on the syllabus. 💀
  • the following functions are Linux extensions:
    • kdk_rti_get_mem_res_total_KiB()
    • kdk_rti_get_mem_res_usage_percent()
    • kdk_rti_get_mem_res_usage_KiB()
    • kdk_rti_get_mem_res_available_KiB()
    • kdk_rti_get_mem_res_free_KiB()
    • kdk_rti_get_mem_virt_alloc_KiB()
    • kdk_rti_get_mem_swap_total_KiB()
    • kdk_rti_get_mem_swap_usage_percent()
    • kdk_rti_get_mem_swap_usage_KiB()
    • kdk_rti_get_mem_swap_free_KiB() and
    • kdk_rti_get_uptime()

💜 SEE ALSO 💜

go read these next, bestie, they're all in the group chat:


🧚 that's the whole page, no notes, no cap. go get those CPU numbers and eat. 💅

and that's a wrap, my love 🎀 this whole thing came out of the Linux Programmer's Manual, dated Mon Sep 18 2023, filed under KDK_RTI_GE...RRENT_USAGE(3) (yes the header is doing a little truncation moment, we don't judge her). bye bestie, go check your CPU usage fr fr 🌸🦋✨

📦 where this page comes from