linux系统中有个符号链接:/proc/self/exe 它代表当前程序;可以采用readlink来获取;
#include <unistd.h>
#include <stdio.h>
int main(int argc , char* argv[])
{
char aucPathBuf[1024] = {0};
char *pcName = NULL;
if( readlink("/proc/self/exe", aucPathBuf,1024) <=0 )
{
return -1;
}
char *pcName = strrchr( aucPathBuf, '/' );
if ( NULL != pcName )
{
printf("pcName:%s\n", ++pcName);
printf("aucPathBuf:%s\n", aucPathBuf);
}
else
{
return -1;
}
return 0;
}