libkysdk-system/man/proc/kdk_get_process_id.3

106 lines
3.2 KiB
Groff
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

.TH "KDK_GET_PROCESS_ID" 3 "Mon Sep 18 2023" "Linux Programmer's Manual" \"
.SH NAME
kdk_get_process_id - 获取某一进程的id
.SH SYNOPSIS
.nf
.B #include <libkyprocess.h>
.sp
.BI "extern int kdk_get_process_id(char *"proc_name ");"
.sp
Link with \fI\-lkyrtinfo\fP.
.SH "Detailed Description"
The main function of the interface is to obtain the PID of the specified process.
.PP
The argument
.I proc_num
is the name of the process.
.SH "RETURN VALUE"
On success, returns the PID of the process of type int.
.PP
On error, return
.BR 0.
.SH EXAMPLES
.EX
#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.1f\n", kdk_get_process_cpu_usage_percent(841));
printf("获取某一进程的内存占用率:%0.1f\n", kdk_get_process_mem_usage_percent(841));
printf("获取某一进程的进程状态:%s\n", kdk_get_process_status(841));
printf("获取某一进程的进程端口号:%d\n", kdk_get_process_port(841));
printf("获取某一进程的启动时间:%s\n", start_time);
printf("获取某一进程的运行时间:%s\n", run_time);
printf("获取某一进程的CPU时间%s\n", cpu_time);
printf("获取某一进程的Command%s\n", cmd);
printf("获取某一进程的属主:%s\n", 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 %s\n", pid[index]);
index ++;
}
kdk_proc_freeall(pid);
char** info = kdk_get_process_all_information();
size_t count = 0;
while (info[count])
{
printf("No. %d\t %s\n", count + 1, info[count]);
count ++;
}
kdk_proc_freeall(info);
char *name = kdk_get_process_name(1151571);
printf("name = %s\n", name);
free(name);
int id = kdk_get_process_id("systemd");
printf("pid %d\n", id);
return 0;
}
.SH "CONFORMING TO"
These functions are as per the withdrawn POSIX.1e draft specification.
The following functions are Linux extensions:
.BR kdk_get_process_name (),
.BR kdk_get_process_cpu_usage_percent (),
.BR kdk_get_process_mem_usage_percent (),
.BR kdk_get_process_status (),
.BR kdk_get_process_port (),
.BR kdk_get_process_start_time (),
.BR kdk_get_process_running_time (),
.BR kdk_get_process_cpu_time (),
.BR kdk_get_process_command (),
.BR kdk_get_process_user (),
.BR kdk_procname_get_process_infomation (),
.BR kdk_get_process_all_information ()
and
.BR kdk_proc_freeall ().
.SH "SEE ALSO"
.BR kdk_get_process_name (3),
.BR kdk_get_process_cpu_usage_percent (3),
.BR kdk_get_process_mem_usage_percent (3),
.BR kdk_get_process_status (3),
.BR kdk_get_process_port (3),
.BR kdk_get_process_start_time (),
.BR kdk_get_process_running_time (3),
.BR kdk_get_process_cpu_time (3),
.BR kdk_get_process_command (3),
.BR kdk_get_process_user (3),
.BR kdk_procname_get_process_infomation (3),
.BR kdk_get_process_all_information (3)
and
.BR kdk_proc_freeall (3).