KDK_RTI_GET_UPTIME(3)

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

okay so bestie, you've landed on the KDK_RTI_GET_UPTIME(3) page — yep, that's the full name, and it lives in the Library Functions Manual 📖✨. It's the one that tells you how long your OS has been awake. Let's get into it 🫶


🌸 NAME 🌸

kdk_rti_get_uptime — 获取操作系统开机时长 (which is literally "get the operating system's uptime", iykyk 💅)


✨ SYNOPSIS ✨

#include <libkyrtinfo.h>

extern int kdk_rti_get_uptime(unsigned int *day, unsigned int *hour, unsigned int *min, unsigned int *sec);

And don't forget to link with -lkyrtinfo, bestie — the linker will NOT find it on its own, I promise 😭


🦋 Detailed Description 🦋

The main function of this interface is to grab the operating system's boot time. That's the whole job, and she does it well 💖

Now the args, one by one, no skipping:

  • day — the number of days 🗓️
  • hour — the number of hours ⏰
  • min — the number of minutes 🕐
  • sec — the number of seconds ⏱️

Like, you hand her four pointers and she fills them in with the uptime broken into those units. Iconic behavior fr fr 👑


💜 RETURN VALUE 💜

  • On success, return 0 🎉
  • On error, return -1 💀

That's it, that's the whole vibe check. Zero means slay, negative one means something went sideways 😭


🎀 EXAMPLES 🎀

Okay so here's the example straight off the page — copying it verbatim, character for character, because we do NOT mess with code around here 🙈

#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 she declares unsigned int day, hour, min, sec;, passes all four by address with &, and then prints them out as 天/小时/分钟/秒? That's the pattern, bestie 🌟


👑 CONFORMING TO 👑

These functions are as per the withdrawn POSIX.1e draft specification ⚰️ (withdrawn, not current — don't @ me, that's what the page says).

The following functions are Linux extensions, so they're the extra-special Linux-only girlies 🌈:

  • 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()
  • kdk_rti_get_cpu_current_usage()

🌈 SEE ALSO 🌈

Go read her friends too, they're all in the same friend group 🫶:


and that's the whole page, bestie 💖✨

Credit where it's due: this one comes from the Linux Programmer's Manual, dated Mon Sep 18 2023, and the page signature is KDK_RTI_GET_UPTIME(3). Now go call kdk_rti_get_uptime() and tell your OS how long she's been awake, periodt 💅🎀

📦 where this page comes from