Skip to content

Instantly share code, notes, and snippets.

@neesenk
Created December 4, 2010 13:29
Show Gist options
  • Save neesenk/728179 to your computer and use it in GitHub Desktop.
Save neesenk/728179 to your computer and use it in GitHub Desktop.
通过pid获取程序名
const char *getprogname_by_pid(int pid)
{
static char path[1024];
static char sympath[32];
int len = 0;
snprintf(sympath, sizeof(sympath), "/proc/%d/exe", pid);
len = readlink(sympath, path, sizeof(path) - 1);
if (len < 0)
return NULL;
path[len] = 0;
return path;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment