KDK_GET_PROCESS_NAME(3)

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

💖 KDK_GET_PROCESS_NAME 💖

okay bestie, so this is kdk_get_process_name(3), a page from the Library Functions Manual, and it's literally all about grabbing the name of a process. no cap. sit down, hydrate, let's go ✨


🌸 NAME 🌸

kdk_get_process_name — 获取某一进程的名称

yes queen, that's the whole vibe: hand over a PID, get a process name back. 🫶


🎀 SYNOPSIS 🎀

#include <libkyprocess.h>

extern char* kdk_get_process_name(int proc_num);

Link with -lkyrtinfo.

so you #include <libkyprocess.h>, you call kdk_get_process_name(int proc_num), and you link with -lkyrtinfo. that's the whole ritual, it's giving very low-effort-slay 💅


🦋 Detailed Description 🦋

the main function of the interface is to obtain the name of the specified process. iconic behaviour honestly.

the argument proc_num is the PID of the process. that's it. that's the input. one int, one dream. 🌈


⭐ RETURN VALUE ⭐

  • on success — returns the name of the process, of type char *. heads up tho: the returned string needs to be released by free. like, it's yours now, you own that memory, take care of it 🎀
  • on error — returns NULL. 😭
not you forgetting to free() and leaking memory... couldn't be you. anyway. free() it. fr fr.

🔥 EXAMPLES 🔥

here's the whole group-chat dump of a demo program, verbatim, no edits:

#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 our girl kdk_get_process_name(1151571) shows up mid-program, gets her moment, prints name = %s, and then gets free(name)'d like a respectful queen? that's the assignment. 👑


💜 CONFORMING TO 💜

these functions are as per the withdrawn POSIX.1e draft specification. (withdrawn!! so vintage, so archival, we love a retro standard 🎀)

the following functions are Linux extensions:

  • 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_procname_get_process_infomation()
  • kdk_get_process_all_information()
  • kdk_proc_freeall()

👑 SEE ALSO 👑

go read the whole squad, they're all linked up:

kdk_get_process_id(3), kdk_get_process_cpu_usage_percent(3), kdk_get_process_mem_usage_percent(3), kdk_get_process_status(3), kdk_get_process_port(3), kdk_get_process_start_time(), kdk_get_process_running_time(3), kdk_get_process_cpu_time(3), kdk_get_process_command(3), kdk_get_process_user(3), kdk_procname_get_process_infomation(3), kdk_get_process_all_information(3) and kdk_proc_freeall(3).


and that's the page!! from the Linux Programmer's Manual, dated Mon Sep 18 2023, filed under KDK_GET_PROCESS_NAME(3) — mwah, go free your strings bestie 💅💖✨

📦 where this page comes from