KDK_GET_PROCESS_PORT(3)
💅 KDK_GET_PROCESS_PORT(3) — Library Functions Manual ✨
okay bestie, sit down, hydrate, and let's talk about kdk_get_process_port from the libkyprocess cinematic universe 💖 this is a Library Functions Manual page, and it's genuinely giving "small function, big feelings" energy.
🌸 NAME 🌸
kdk_get_process_port — 获取某一进程的端口号占用
(that's "grab the port number a process is occupying" for my monolingual girlies 🫶 the original page says it in Chinese and we are not erasing that, periodt)
🎀 SYNOPSIS 🎀
#include <libkyprocess.h>
extern int kdk_get_process_port(int proc_num);
and don't forget to link it, or it simply will not vibe:
Link with -lkyrtinfo.
🦋 Detailed Description 🦋
the whole main-character job of this interface? obtain the port number occupation of the specified process. that's it. that's the function. it's not doing your taxes, it's finding a port 🔥
the argument proc_num is the PID of the process. yes, the PID. not the port. the PID. the port is what you get back. do not mix these up or you will be confused and we will both be sad 😭
⭐ RETURN VALUE ⭐
- On success — returns the port number used of the process, of type
int. slay. - On error — return
0.
ngl bestie, 0 is also a real port number in the abstract, so like… read the room before you assume failure. that's just what the page says, and I'm not adding lore that isn't there 🙈
💀 EXAMPLES 💀
here's the full example, copied character-for-character because we respect the source material 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;
}
see the kdk_get_process_port(841) line in there? that's our girl, doing her one job in the middle of a whole ensemble cast 🎀
🧚 CONFORMING TO 🧚
These functions are as per the withdrawn POSIX.1e draft specification.
and then — plot twist — 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_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().
and yes, that list keeps kdk_procname_get_process_infomation() spelled exactly like that. I do not make the rules, I just keep them fr fr 💅
🌈 SEE ALSO 🌈
go read these next, bestie, they're the friend group 🫶
kdk_get_process_name(3)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_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 whole page, no notes, no skips, every last detail intact ✨
this was the Linux Programmer's Manual version, dated Mon Sep 18 2023 — so like, she's been iconic since 2023 and she's still serving 💖 mwah, go free your strings and check your return value, ily 🎀🦋
📦 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