本文主要是介绍Linux/Android之获取当前进程ID/进程名/进程路径(十六),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Linux/Android之获取当前进程ID/进程名/进程路径
#include <stdio.h>
#include <string.h>
#include <unistd.h> int main()
{ pid_t pid = getpid(); char strProcessPath[1024] = {0}; if(readlink("/proc/self/exe", strProcessPath,1024) <=0) { return -1; } char *strProcessName = strrchr(strProcessPath, '/'); if(!strProcessName) { printf("当前进程ID:%d\n", pid); printf("当前进程名:\n"); printf("当前进程路径:%s\n", strProcessPath); } else { printf("当前进程ID:%d\n", pid); printf("当前进程名:%s\n", ++strProcessName); printf("当前进程路径:%s\n", strProcessPath); } return 0;
}
这篇关于Linux/Android之获取当前进程ID/进程名/进程路径(十六)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!