Merge pull request #800 from jpcima/better-process-name
Better process name
This commit is contained in:
commit
0de8b1cabc
1 changed files with 15 additions and 3 deletions
|
|
@ -318,9 +318,21 @@ std::string getProcessorName()
|
||||||
|
|
||||||
std::string getCurrentProcessName()
|
std::string getCurrentProcessName()
|
||||||
{
|
{
|
||||||
const char* name = __progname;
|
std::string name;
|
||||||
if (!name)
|
|
||||||
return std::string();
|
const std::string commPath = "/proc/" + std::to_string(getpid()) + "/comm";
|
||||||
|
|
||||||
|
if (std::ifstream in { commPath, std::ios::binary }) {
|
||||||
|
name.reserve(256);
|
||||||
|
for (int c; (c = in.get()) != std::char_traits<char>::eof() && c != '\n'; )
|
||||||
|
name.push_back(static_cast<unsigned char>(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.empty()) {
|
||||||
|
if (const char* progname = __progname)
|
||||||
|
name.assign(progname);
|
||||||
|
}
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue