Skip to content

Commit ccd5853

Browse files
committed
support detecting process name on MAC
1 parent af0e481 commit ccd5853

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/ProcessDetails.cxx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
#include <unistd.h>
99

10+
#ifdef _OS_MAC
11+
#include <mach-o/dyld.h>
12+
#endif
13+
1014
namespace AliceO2
1115
{
1216
/// ALICE O2 Monitoring system
@@ -28,14 +32,25 @@ inline void ProcessDetails::generatePid()
2832
inline void ProcessDetails::generateProcessName()
2933
{
3034
char buff[255];
35+
#ifdef _OS_LINUX
3136
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
3237
if (len != -1) {
3338
buff[len] = '\0';
3439
mProcessName = std::string(buff);
35-
mProcessName = mProcessName.substr(mProcessName.find_last_of("/") + 1);
3640
}
37-
else {
41+
#endif
42+
43+
#ifdef _OS_MAC
44+
uint32_t size = sizeof(buff);
45+
if (_NSGetExecutablePath(buff, &size) == 0) {
46+
mProcessName = std::string(buff);
47+
}
48+
#endif
49+
50+
if (mProcessName.empty()) {
3851
mProcessName = "!";
52+
} else {
53+
mProcessName = mProcessName.substr(mProcessName.find_last_of("/") + 1);
3954
}
4055
}
4156

0 commit comments

Comments
 (0)