KDK_GET_PR...NNING_TIME(3)

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

💖 KDK_GET_PR...NNING_TIME(3) 💖

okay so bestie, we're in the Library Functions Manual today and the function we're stanning is kdk_get_process_running_time 💅 buckle up.


✨ NAME ✨

kdk_get_process_running_time — 获取某一进程的运行时间

like. it tells you how long a process has been running. that's it. that's the whole vibe. 🕰️


🌸 SYNOPSIS 🌸

#include <libkyprocess.h>

extern char* kdk_get_process_running_time(int proc_num);

and don't forget to link it, bestie:

Link with -lkyrtinfo.

🦋 Detailed Description 🦋

The main function of the interface is to obtain the running time of the specified process. 💫

The argument proc_num is the PID of the process. that's your lil ticket to the process you're curious about, no cap.


🎀 RETURN VALUE 🎀

  • On success — you get the running time of the process, of type char*, looking all cute like "0-09:06:15" ✨. heads up: the returned string needs to be released by free, or it's just gonna sit there forever and that's not the vibe. 🫶
  • On error — you get NULL. it's giving nothing. it's giving void. 😭

🌈 EXAMPLES 🌈

here's the whole thing in action, queen energy:

#include "libkyprocess.h"
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char *run_time = kdk_get_process_running_time(841);
    char *cpu_time = kdk_get_process_cpu_time(841);
    char *cmd = kdk_get_process_command(841);
    char *start_time = kdk_get_process_start_time(841);
    printf("获取某一进程的CPU利用率:%0.1f0, kdk_get_process_cpu_usage_percent(841));
    printf("获取某一进程的内存占用率:%0.1f0, kdk_get_process_mem_usage_percent(841));
    printf("获取某一进程的进程状态:%s0, kdk_get_process_status(841));
    printf("获取某一进程的进程端口号:%d0, kdk_get_process_port(841));
    printf("获取某一进程的启动时间:%s0, start_time);
    printf("获取某一进程的运行时间:%s0, run_time);
    printf("获取某一进程的CPU时间:%s0, cpu_time);
    printf("获取某一进程的Command:%s0, cmd);
    printf("获取某一进程的属主:%s0, kdk_get_process_user(841));
    free(run_time);
    free(cpu_time);
    free(cmd);
    free(start_time);
    char** pid =  kdk_procname_get_process_infomation("systemd");
    size_t index = 0;
    while (pid[index])
    {
        printf("pid %s0, pid[index]);
        index ++;
    }
    kdk_proc_freeall(pid);

    char** info = kdk_get_process_all_information();
    size_t count = 0;
    while (info[count])
    {
        printf("No. %d %s0, count + 1, info[count]);
        count ++;
    }
    kdk_proc_freeall(info);

    char *name = kdk_get_process_name(1151571);
    printf("name = %s0, name);
    free(name);

    int id =  kdk_get_process_id("systemd");
    printf("pid %d0, id);

    return 0;
}

see how every char* gets its free? that's the self-care routine, fr fr. 🧖‍♀️


👑 CONFORMING TO 👑

These functions are as per the withdrawn POSIX.1e draft specification. (withdrawn, bestie — it's a vintage, it's an archive, it's giving 2001) 💀

The following functions are Linux extensions:

  • kdk_get_process_name()
  • kdk_get_process_id()
  • kdk_get_process_cpu_usage_percent()
  • kdk_get_process_mem_usage_percent()
  • kdk_get_process_status()
  • kdk_get_process_port()
  • kdk_get_process_start_time()
  • kdk_get_process_cpu_time()
  • kdk_get_process_command()
  • kdk_get_process_user()
  • kdk_procname_get_process_infomation()
  • kdk_get_process_all_information()
  • kdk_proc_freeall()

💜 SEE ALSO 💜

go read these next, they're the friend group:


ngl, some of the printf format strings in that example are looking a little chaotic — but that's exactly what the page says, so I'm not touching a single character. 🙈

and that's the whole page, bestie!! 💖✨

this came from the Linux Programmer's Manual, dated Mon Sep 18 2023, and it lives under the name KDK_GET_PR...NNING_TIME(3) — slay, go forth and check your process runtimes responsibly, mwah 💅🎀🦋

📦 where this page comes from