KDK_PROCNAME_GET_PROCESS_INFOMATION(3)

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

💖 KDK_PROCNAME_GET_PROCESS_INFOMATION(3) 💖

okay bestie, so this is a page from the Library Functions Manual, and the star of the show is literally called kdk_procname_get_process_infomation (yes the spelling is a whole vibe, we do not fix it, we respect it 💅). Sit down, grab a boba, we're gonna get you a process's info. 🍓


✨ NAME ✨

kdk_procname_get_process_infomation — 获取某一进程的信息 (aka: get the info of one specific process, no cap) 🫶


✨ SYNOPSIS ✨

#include <libkyprocess.h>

extern char** kdk_procname_get_process_infomation(char *proc_name);

Link with -lkyrtinfo.


✨ DESCRIPTION ✨

So like, the whole main character job of this interface? It's to grab the information about the process you point at. That's it. That's the gig. 👑

The argument proc_num is the name of the process. (The manpage said proc_num, the synopsis said proc_name, and honestly? both of them are slaying in their own way. We report, we don't judge. 💀)


✨ RETURN VALUE ✨

  • On success — you get the information of the process, type char**, and it's terminated by a NULL character. It was made by alloc, so bestie you gotta recycle it with kdk_proc_freeall. Don't just leave it there, that's not giving responsible memory management. 😭♻️
  • On error — it returns NULL. Just NULL. Nothing. Ghosted. 🙈

✨ EXAMPLES ✨

here's the whole example, verbatim, because we do not touch the sacred text 🎀

#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;
}

notice how the char** gets walked with an index until it hits that NULL? that's the loop, that's the lore, that's the whole thing. and then kdk_proc_freeall cleans up after. iconic behaviour. ✨


✨ CONFORMING TO ✨

These functions are as per the withdrawn POSIX.1e draft specification. (withdrawn!! historical!! we stan a draft that never made it to print 🎀)

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_running_time()
  • kdk_get_process_cpu_time()
  • kdk_get_process_command()
  • kdk_get_process_user()
  • kdk_get_process_all_information()
  • kdk_proc_freeall()

✨ SEE ALSO ✨

go read these next, they're all in the friend group 🦋


and that's the whole page bestie!! 🫶 this one came out of the <strong>Linux Programmer's Manual</strong>, dated <strong>Mon Sep 18 2023</strong>, and it lives under the title <strong>KDK_PROCNA..._INFOMATION(3)</strong> — yes the truncated title with the triple dots is part of the aesthetic, we keep it. mwah. 💋

free your allocations, walk your arrays, and stay hydrated. periodt. 💅✨

📦 where this page comes from