-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcess.cpp
116 lines (96 loc) · 3.49 KB
/
Process.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/***************************************************************************
The Base Framework
A framework for developing platform independent applications
See COPYRIGHT.txt for details.
This framework is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
For the licensing terms refer to the file 'LICENSE'.
***************************************************************************/
#include <base/Application.h>
#include <base/concurrency/Process.h>
#include <base/TypeInfo.h>
#include <base/security/User.h>
using namespace com::azure::dev::base;
class ProcessApplication : public Application {
private:
static const unsigned int MAJOR_VERSION = 1;
static const unsigned int MINOR_VERSION = 0;
public:
ProcessApplication()
: Application("Process")
{
}
void dumpLimit(
const Literal& literal,
OperatingSystem::Resource resource) {
int64 softLimit = OperatingSystem::getResourceLimit(
resource,
OperatingSystem::SOFT_LIMIT
);
int64 hardLimit = OperatingSystem::getResourceLimit(
resource,
OperatingSystem::HARD_LIMIT
);
fout << indent(2) << literal << " (soft): ";
if (softLimit == -1) {
fout << "INFINITE";
} else {
fout << softLimit;
}
fout << ENDL;
fout << indent(2) << literal << " (hard): ";
if (hardLimit == -1) {
fout << "INFINITE";
} else {
fout << hardLimit;
}
fout << ENDL;
}
void main()
{
fout << getFormalName() << " version "
<< MAJOR_VERSION << '.' << MINOR_VERSION << EOL
<< "The Base Framework (Test Suite)" << EOL
<< ENDL;
fout << "Is administrator: " << User::getCurrentUser().isAdmin() << ENDL;
fout << "Current user: " << User::getCurrentUser().getName() << ENDL;
fout << "Current process: " << Process::getProcess().getId() << ENDL;
fout << "Parent process: " << Process::getParentProcess().getId() << ENDL;
fout << "Name of process: ";
try {
fout << Process::getProcess().getName();
} catch (NotSupported&) {
fout << "unknown";
}
fout << ENDL;
fout << "Is parent process alive: ";
try {
fout << Process::getParentProcess().isAlive();
} catch (Process::ProcessException&) {
fout << "unknown";
}
fout << ENDL;
fout << "Priority of process: "
<< Process::getProcess().getPriority() << ENDL;
fout << "Priority of parent process: "
<< Process::getParentProcess().getPriority() << ENDL;
fout << "Number of configured processors: "
<< Process::getNumberOfConfiguredProcessors() << ENDL;
fout << "Number of online processors: "
<< Process::getNumberOfOnlineProcessors() << ENDL;
fout << ENDL;
fout << "Resource limits: " << ENDL;
dumpLimit(MESSAGE("Core file size"), OperatingSystem::RESOURCE_CORE);
dumpLimit(MESSAGE("CPU time"), OperatingSystem::RESOURCE_CPU);
dumpLimit(MESSAGE("Data segment size"), OperatingSystem::RESOURCE_DATA);
dumpLimit(MESSAGE("File size"), OperatingSystem::RESOURCE_FILE_SIZE);
dumpLimit(MESSAGE("Number of open files"), OperatingSystem::RESOURCE_OPEN_FILES);
dumpLimit(MESSAGE("Stack size"), OperatingSystem::RESOURCE_STACK);
dumpLimit(MESSAGE("Address space"), OperatingSystem::RESOURCE_ADDRESS_SPACE);
// wait
// terminate
// Process::execute(self img);
}
};
APPLICATION_STUB(ProcessApplication);