KDK_GET_PROCESS_STATUS(3)

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

💖 KDK_GET_PROCESS_STATUS(3) 💖

okay bestie, so we're in the Library Functions Manual section, and today's main character is kdk_get_process_status — yes, the whole page is literally named after it, iconic behavior only 💅


✨ NAME ✨

kdk_get_process_status — 获取某一进程的进程状态 (a.k.a. it goes and gets the process status of a process, no cap)


🌸 SYNOPSIS 🌸

#include <libkyprocess.h>

extern char* kdk_get_process_status(int proc_num);

Link with -lkyrtinfo.

fr fr, don't forget that link flag or nothing is gonna work and you'll be sad 😭

🦋 Detailed Description 🦋

So the main function of this interface — like, its whole ~purpose~ — is to obtain the process state of the specified process. That's it. That's the vibe.

The argument proc_num is the PID of the process. That's the number you gotta hand over, bestie. Give it the PID, it gives you the status. Simple as. ✨


🎀 RETURN VALUE 🎀

  • On success, returns the process state of the process of type char* — slay! 💖
  • The returned string needs to be released by free — yes queen, you have to clean up after yourself, no leaving your mess for the next girl 🙈

On error, return NULL.

so if you get NULL back, something went wrong. check your PID, check your life choices, breathe, try again 🫶

🌈 EXAMPLES 🌈

okay here's the whole demo, verbatim, every single line, because we do NOT skip details in this house 👑

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

like… look at all those calls. CPU usage, memory usage, status, port, start time, running time, CPU time, command, user — the whole friend group showed up 💀 and then free() on all the char* besties, because again, we clean up. Then it loops through kdk_procname_get_process_infomation("systemd") results and frees them with kdk_proc_freeall(pid), then does the same dance with kdk_get_process_all_information() and kdk_proc_freeall(info), then grabs a name for PID 1151571 and frees it, then gets the id for "systemd". chef's kiss 👩‍🍳💋


💜 CONFORMING TO 💜

These functions are as per the withdrawn POSIX.1e draft specification. (withdrawn!! rip boo, but we move 🕊️)

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_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 these next, bestie, it's a whole saga:


and that's the whole page, bestie 💅✨ this lil masterpiece comes to you from the Linux Programmer's Manual, dated Mon Sep 18 2023 — so yeah, timestamped and everything, periodt. now go get that process status and remember to free() it 🎀🦋💖

📦 where this page comes from