Created
December 4, 2010 13:29
-
-
Save neesenk/728179 to your computer and use it in GitHub Desktop.
通过pid获取程序名
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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