Linuxで現在のプロセスID、プロセス名、プロセスパスを取得


#include 
#include 
#include 

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
", pid); printf(" :
"); printf(" :%s
", strProcessPath); } else { printf(" ID:%d
", pid); printf(" :%s
", ++strProcessName); printf(" :%s
", strProcessPath); } return 0; }