Make get_process_name_by_pid more robust and cross-platform by falling back to $SHELL environment variable

This commit is contained in:
Ryan Baumann 2015-02-22 16:25:30 -05:00
parent 32683a3876
commit d0d346a094

View file

@ -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)*sizeof(name));
}
}
return name;
}