libDwm-0.6.0
DwmProcessInfo.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmProcessInfo.hh 9018 $
3 // @(#) $Id: DwmProcessInfo.hh 9018 2017-04-11 20:05:43Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2006-2007, 2016
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
33 // OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMPROCESSINFO_HH_
43 #define _DWMPROCESSINFO_HH_
44 
45 extern "C" {
46  #ifdef HAVE_KVM_H
47  #include <kvm.h>
48  #endif
49  #include <sys/param.h>
50  #include <sys/sysctl.h>
51  #include <sys/user.h>
52  #include <inttypes.h>
53 #ifdef __linux__
54  #include <proc/readproc.h>
55 #endif
56 }
57 
58 #include <string>
59 #include <vector>
60 
61 #include "DwmGZReadable.hh"
62 #include "DwmGZWritable.hh"
63 #include "DwmReadable.hh"
64 #include "DwmRusage.hh"
65 #include "DwmTimeValue.hh"
66 #include "DwmWritable.hh"
67 
68 namespace Dwm {
69 
70  //--------------------------------------------------------------------------
72  //--------------------------------------------------------------------------
74  : public Readable, public Writable,
75  public GZReadable, public GZWritable
76  {
77  public:
78  ProcessInfo();
79 
80  //------------------------------------------------------------------------
83  //------------------------------------------------------------------------
84  ProcessInfo(pid_t pid);
85 
86 #if (defined(__FreeBSD__) || defined(__APPLE__))
87  ProcessInfo(const struct kinfo_proc & proc);
88 #elif (defined __OpenBSD__)
89  ProcessInfo(const struct kinfo_proc2 & proc);
90 #elif (defined __linux__)
91  ProcessInfo(proc_t *proc);
92 #endif
93 
94  //------------------------------------------------------------------------
96  //------------------------------------------------------------------------
97  virtual ~ProcessInfo();
98 
99  //------------------------------------------------------------------------
101  //------------------------------------------------------------------------
102  pid_t Id() const;
103 
104  //------------------------------------------------------------------------
106  //------------------------------------------------------------------------
107  pid_t ParentId() const;
108 
109  //------------------------------------------------------------------------
111  //------------------------------------------------------------------------
112  pid_t GroupId() const;
113 
114  //------------------------------------------------------------------------
116  //------------------------------------------------------------------------
117  const std::string & ControllingTty() const;
118 
119  pid_t SessionId() const;
120 
121  //------------------------------------------------------------------------
123  //------------------------------------------------------------------------
124  uid_t EffectiveUserId() const;
125 
126  //------------------------------------------------------------------------
128  //------------------------------------------------------------------------
129  std::string EffectiveUserName() const;
130 
131  //------------------------------------------------------------------------
133  //------------------------------------------------------------------------
134  uid_t RealUserId() const;
135 
136  //------------------------------------------------------------------------
138  //------------------------------------------------------------------------
139  std::string RealUserName() const;
140 
141  //------------------------------------------------------------------------
143  //------------------------------------------------------------------------
144  uid_t SavedEffectiveUserId() const;
145 
146  //------------------------------------------------------------------------
148  //------------------------------------------------------------------------
149  std::string SavedEffectiveUserName() const;
150 
151  //------------------------------------------------------------------------
153  //------------------------------------------------------------------------
154  uid_t RealGroupId() const;
155 
156  //------------------------------------------------------------------------
158  //------------------------------------------------------------------------
159  uid_t SavedEffectiveGroupId() const;
160 
161  //------------------------------------------------------------------------
163  //------------------------------------------------------------------------
164  const std::string & Command() const;
165 
166  //------------------------------------------------------------------------
168  //------------------------------------------------------------------------
169  const std::vector<std::string> & Args() const;
170 
171  //------------------------------------------------------------------------
173  //------------------------------------------------------------------------
174  const TimeValue & StartTime() const;
175 
176  //------------------------------------------------------------------------
178  //------------------------------------------------------------------------
179  uint32_t Size() const;
180 
181  //------------------------------------------------------------------------
183  //------------------------------------------------------------------------
184  uint32_t ResidentSetSize() const;
185 
186  //------------------------------------------------------------------------
188  //------------------------------------------------------------------------
189  const Dwm::Rusage & Rusage() const;
190 
191  //------------------------------------------------------------------------
193  //------------------------------------------------------------------------
194  bool operator == (const ProcessInfo & process) const;
195 
196  //------------------------------------------------------------------------
198  //------------------------------------------------------------------------
199  std::istream & Read(std::istream & is);
200 
201  //------------------------------------------------------------------------
203  //------------------------------------------------------------------------
204  std::ostream & Write(std::ostream & os) const;
205 
206  //------------------------------------------------------------------------
209  //------------------------------------------------------------------------
210  int Read(gzFile gzf);
211 
212  //------------------------------------------------------------------------
215  //------------------------------------------------------------------------
216  int Write(gzFile gzf) const;
217 
218  //------------------------------------------------------------------------
220  //------------------------------------------------------------------------
221  ssize_t Read(int fd);
222 
223  //------------------------------------------------------------------------
225  //------------------------------------------------------------------------
226  ssize_t Write(int fd) const;
227 
228  //------------------------------------------------------------------------
230  //------------------------------------------------------------------------
231  size_t Read(FILE * f);
232 
233  //------------------------------------------------------------------------
235  //------------------------------------------------------------------------
236  size_t Write(FILE *f) const;
237 
238  //------------------------------------------------------------------------
241  //------------------------------------------------------------------------
242  uint32_t StreamedLength() const;
243 
244  //------------------------------------------------------------------------
247  //------------------------------------------------------------------------
248  void AddArg(const char *arg);
249 
250  private:
251  pid_t _id;
252  pid_t _parentId;
253  pid_t _groupId;
254  std::string _controllingTty;
255  pid_t _sessionId;
256  pid_t _terminalSessionId;
257  uid_t _effectiveUserId;
258  uid_t _realUserId;
259  uid_t _savedEffectiveUserId;
260  uid_t _realGroupId;
261  uid_t _savedEffectiveGroupId;
262  std::string _command;
263  TimeValue _startTime;
264  uint32_t _size;
265  uint32_t _residentSetSize;
266  Dwm::Rusage _rusage;
267  std::vector<std::string> _args;
268 
269  };
270 
271 } // namespace Dwm
272 
273 #endif // _DWMPROCESSINFO_HH_
274 
275 //---------------------------- emacs settings -----------------------------
276 // Local Variables:
277 // mode: C++/la
278 // tab-width: 2
279 // indent-tabs-mode: nil
280 // c-basic-offset: 2
281 // End:
282 //-------------------------------------------------------------------------
Dwm::Rusage class definition.
pid_t Id() const
Returns the process ID.
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmGZWritable.hh:57
This class encapsulates a time value beyond the UNIX epoch, with microsecond granularity.
Definition: DwmTimeValue.hh:72
Dwm::Writable pure virtual class definition.
uint32_t ResidentSetSize() const
Returns the resident set size of the process (in bytes).
pid_t GroupId() const
Returns the process group ID.
Dwm::GZReadable pure virtual class definition.
Dwm::Readable pure virtual class definition.
This class encapsulates struct rusage and getrusage() functionality.
Definition: DwmRusage.hh:65
std::string EffectiveUserName() const
Returns the username of the effective user ID.
const std::string & ControllingTty() const
Returns the controlling tty name.
uint32_t StreamedLength() const
Returns the number of bytes that would be written if we called one of the Write() members...
std::string RealUserName() const
Returns the username of the real user ID.
uid_t RealUserId() const
Returns the real user ID.
uid_t RealGroupId() const
Returns the real process group ID.
Encapsulates information about a single process.
Definition: DwmProcessInfo.hh:73
const std::vector< std::string > & Args() const
Returns the argument list.
const std::string & Command() const
Returns the command.
Dwm::TimeValue class definition.
uid_t EffectiveUserId() const
Returns the effective user ID.
Definition: DwmBZ2IO.hh:67
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition: DwmGZReadable.hh:57
pid_t ParentId() const
Returns the parent process ID.
bool operator==(const ProcessInfo &process) const
operator ==
const TimeValue & StartTime() const
Returns the proces start time.
This class defines an interface for classes that can write their contents to an ostream, file descriptor or FILE pointer.
Definition: DwmWritable.hh:58
Dwm::GZWritable pure virtual class definition.
uid_t SavedEffectiveUserId() const
Returns the saved effective user ID.
This class defines an interface for classes that can read their contents from an istream, file descriptor or FILE pointer.
Definition: DwmReadable.hh:58
std::string SavedEffectiveUserName() const
Returns the username of the saved effective user ID.
uid_t SavedEffectiveGroupId() const
Returns the saved effective group ID.
const Dwm::Rusage & Rusage() const
Returns the process rusage.
std::ostream & Write(std::ostream &os) const
Writes to an ostream. Returns the ostream.
uint32_t Size() const
Returns the virtual size of the process (in bytes).
std::istream & Read(std::istream &is)
Reads from an istream. Returns the istream.
void AddArg(const char *arg)
Adds an argument to the list of args.