Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make get_process_name_by_pid more robust and cross-platform (see: #127) #132

Merged
merged 2 commits into from Feb 23, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/hstr_utils.c
Expand Up @@ -144,6 +144,14 @@ char *get_process_name_by_pid(const int pid)
fclose(f);
}
}
// if name isn't e.g. bash/zsh at this point, fall back to $SHELL
if(strlen(name) > 4){
char* shell = strrchr(getenv("SHELL"),'/');
if(shell != NULL){
shell++;
strncpy(name,shell,sizeof(char)*strlen(shell));
}
}
return name;
}

Expand Down