KDK_GET_PROCESS_ID(3)
💖 KDK_GET_PROCESS_ID(3) 💖
okay bestie, gather round, because we're diving into kdk_get_process_id — a lil function from the Library Functions Manual that does exactly one thing and does it gorgeously: it finds the PID of a process for you. no cap. 🎀
✨ NAME ✨
kdk_get_process_id — 获取某一进程的id 🫶
(that's "get the id of a certain process" for anyone who doesn't read Chinese, and yes, it's as simple as it sounds, periodt.)
🌸 SYNOPSIS 🌸
#include <libkyprocess.h>
extern int kdk_get_process_id(char *proc_name);
Link with -lkyrtinfo.
🦋 heads up: you gotta link with -lkyrtinfo or nothing's gonna work, bestie. no shortcuts. 💅
🧚 Detailed Description 🧚
The main function of the interface is to obtain the PID of the specified process. like, that's the whole vibe. it's giving "one job, doing it well." 👑
The argument proc_num is the name of the process.
💀 not me noticing that the synopsis calls itproc_nameand the description calls itproc_num… anyway, that's literally what the page says, so I'm passing it along verbatim, iykyk. 🙈
🌈 RETURN VALUE 🌈
- On success, returns the PID of the process of type
int. slay. 💖 - On error, return
0.
⭐ so if you get 0 back, that's not a PID, that's the universe telling you something went sideways. just so you know. 🫶
🍓 EXAMPLES 🍓
okay this example is a whole meal, it's doing the absolute most and I respect it:
#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 that int id = kdk_get_process_id("systemd"); at the bottom? that's our girl. main character energy fr fr. 🔥
💜 CONFORMING TO 💜
These functions are as per the withdrawn POSIX.1e draft specification.
The following functions are Linux extensions: kdk_get_process_name(), 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() and kdk_proc_freeall().
🎀 "withdrawn POSIX.1e draft specification" — okay vintage queen, we see you, and we love you anyway. the rest are Linux extensions, so don't go expecting them on your weird uncle's BSD box. 😭
👑 SEE ALSO 👑
kdk_get_process_name(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)andkdk_proc_freeall(3)
(yes, kdk_get_process_start_time() in that list has no (3) on it — that's literally how it's written, don't come for me. 💅)
and that's the whole page, bestie!! 🌸✨ this lil cutie lives in the Linux Programmer's Manual, dated Mon Sep 18 2023, and honestly? iconic. go get those PIDs, you absolute legend. mwah. 💖🦋🎀🫶🌟
📦 where this page comes from
- arch rolling: libkysdk-system 3.0.1.4-1 · LGPL-3.0-or-later AND LGPL-2.1-only OR LGPL-3.0-only AND LGPL-2.1-only WITH Qt-LGPL-exception-1.1 OR LGPL-3.0-only WITH Qt-LGPL-exception-1.1 AND MIT
- ubuntu resolute: libkysdk-system-dev 3.0.1.2-0ubuntu1 · LGPL-3.0-only
- ubuntu stonking: libkysdk-system-dev 3.0.1.3-0ubuntu1 · LGPL-3.0-or-later
- 💖 girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms