From 1b3a5d652c92cf5b091964110f4ba1251acbf9f4 Mon Sep 17 00:00:00 2001 From: Ted Ross Date: Tue, 24 Feb 2009 14:15:28 +0000 Subject: QPID-1676 - Added client process name and pid to connection object for management. Supported in C++, Python, and Ruby clients. Still needs to be added to the Java clients. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@747389 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/sys/SystemInfo.h | 5 +++++ cpp/src/qpid/sys/posix/SystemInfo.cpp | 24 ++++++++++++++++++++++++ cpp/src/qpid/sys/windows/SystemInfo.cpp | 19 +++++++++++++++++++ 3 files changed, 48 insertions(+) (limited to 'cpp/src/qpid/sys') diff --git a/cpp/src/qpid/sys/SystemInfo.h b/cpp/src/qpid/sys/SystemInfo.h index d43fe34b04..017a05e2c5 100644 --- a/cpp/src/qpid/sys/SystemInfo.h +++ b/cpp/src/qpid/sys/SystemInfo.h @@ -73,6 +73,11 @@ namespace SystemInfo { */ uint32_t getParentProcessId(); + /** + * Get the name of the current process (i.e. the name of the executable) + */ + std::string getProcessName(); + }}} // namespace qpid::sys::SystemInfo diff --git a/cpp/src/qpid/sys/posix/SystemInfo.cpp b/cpp/src/qpid/sys/posix/SystemInfo.cpp index 938d4861c4..5d9eda605d 100755 --- a/cpp/src/qpid/sys/posix/SystemInfo.cpp +++ b/cpp/src/qpid/sys/posix/SystemInfo.cpp @@ -27,6 +27,9 @@ #include #include #include +#include +#include +#include #ifndef HOST_NAME_MAX # define HOST_NAME_MAX 256 @@ -104,6 +107,27 @@ uint32_t SystemInfo::getParentProcessId() return (uint32_t) ::getppid(); } +string SystemInfo::getProcessName() +{ + uint32_t pid = getProcessId(); + string value; + + stringstream pathStream; + pathStream << "/proc/" << pid << "/status"; + ifstream input(pathStream.str().c_str()); + if (input.good()) { + while (!input.eof()) { + string key; + input >> key; + if (key == "Name:") { + input >> value; + break; + } + } + input.close(); + } + return value; +} }} // namespace qpid::sys diff --git a/cpp/src/qpid/sys/windows/SystemInfo.cpp b/cpp/src/qpid/sys/windows/SystemInfo.cpp index b887cac58b..dc5c56b6fb 100755 --- a/cpp/src/qpid/sys/windows/SystemInfo.cpp +++ b/cpp/src/qpid/sys/windows/SystemInfo.cpp @@ -155,6 +155,25 @@ void SystemInfo::getSystemId (std::string &osName, machine = "unknown"; break; } + +uint32_t SystemInfo::getProcessId() +{ + // TODO: Provide Windows implementation + return 0; +} + +uint32_t SystemInfo::getParentProcessId() +{ + // TODO: Provide Windows implementation + return 0; +} + +std::string SystemInfo::getProcessName() +{ + // TODO: Provide Windows implementation + return std::string(); +} + } }} // namespace qpid::sys -- cgit v1.2.1