RSC  0.16.0
PosixProcessInfo.cpp
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is part of the RSC project
4  *
5  * Copyright (C) 2014 Jan Moringen
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #include "ProcessInfo.h"
28 
29 #include <sys/types.h> // for getpwuid(3)
30 #include <pwd.h> // likewise
31 #include <unistd.h> // for getuid(2)
32 
33 #include <boost/date_time/posix_time/posix_time.hpp>
34 
35 namespace rsc {
36 namespace os {
37 
38 unsigned int currentProcessId() {
39  return getpid(); // cannot fail according to getpid(2)
40 }
41 
42 std::string getProgramName(PID /*pid*/) {
43  throw std::runtime_error("Could not determine program name: not"
44  " supported");
45 }
46 
47 std::string currentProgramName() {
49 }
50 
51 std::vector<std::string> getCommandlineArguments(PID /*pid*/) {
52  throw std::runtime_error("Could not determine commandline arguments:"
53  " not supported");
54 }
55 
56 std::vector<std::string> currentCommandlineArguments() {
58 }
59 
60 std::string getExecutablePath(PID /*pid*/) {
61  throw std::runtime_error("Could not determine executable path:"
62  " not supported");
63 }
64 
65 std::string currentExecutablePath() {
67 }
68 
69 boost::posix_time::ptime getProcessStartTime(PID /*pid*/) {
70  throw std::runtime_error("Could not determine process start time:"
71  " not supported");
72 }
73 
74 boost::posix_time::ptime currentProcessStartTime() {
76 }
77 
78 std::string getExecutingUser(PID /*pid*/) {
79  throw std::runtime_error("Could not determine executing user:"
80  " not supported");
81 }
82 
83 std::string currentExecutingUser() {
84  passwd* entry = getpwuid(getuid());
85  return entry->pw_name;
86 }
87 
88 }
89 }
std::vector< std::string > getCommandlineArguments(PID pid)
Return the list of commandline arguments of the process designated by pid.
boost::posix_time::ptime getProcessStartTime(PID pid)
Return the start time of the process designated by pid.
PID currentProcessId()
Return the id the current process.
boost::posix_time::ptime currentProcessStartTime()
Return the start time of the current process.
std::string getExecutablePath(PID pid)
Return the absolute path of the executable file that is executed in the process designated by pid...
std::vector< std::string > currentCommandlineArguments()
Return the list of commandline arguments of the current process.
std::string getExecutingUser(PID pid)
Return login- or account-name of the user executing pid.
std::string currentExecutingUser()
Return the login- or account-name of the user executing the current process.
std::string getProgramName(PID pid)
Return the name of the program executed in the process designated by pid.
unsigned int PID
Definition: ProcessInfo.h:47
std::string currentProgramName()
Return the name of the program executed in the current process.
std::string currentExecutablePath()
Return the absolute path of the executable file that is executed in the current process.