14 #include <sys/types.h>
17 #include <netinet/in.h>
18 #include <sys/statvfs.h>
27 std::ifstream temperatureFile;
28 const std::string parsePath =
"/sys/class/thermal/" + thermalZone +
"/temp";
29 temperatureFile.open(parsePath);
33 while (std::getline(temperatureFile, line)) {
34 auto unused = scanf(line.c_str(),
"%ld", &temperature);
37 temperatureFile.close();
43 auto dp = opendir(
"/proc");
46 while (pid < 0 && (dirp = readdir(dp))) {
47 int id = atoi(dirp->d_name);
49 std::string cmdPath{
"/proc/"};
50 cmdPath.append(dirp->d_name);
51 cmdPath.append(
"/cmdline");
52 std::ifstream cmdFile(cmdPath.c_str());
54 getline(cmdFile, cmdLine);
55 if (!cmdLine.empty()) {
56 size_t pos = cmdLine.find(
'\0');
57 if (pos != std::string::npos)
58 cmdLine = cmdLine.substr(0, pos);
59 pos = cmdLine.rfind(
'/');
60 if (pos != std::string::npos)
61 cmdLine = cmdLine.substr(pos + 1);
62 if (strcmp(procName.c_str(), cmdLine.c_str()) == 0) {
75 throw std::runtime_error(
76 "Nothing to Kill, no Process " + procName +
" PID " +
std::to_string(pid));
78 int ret = kill(pid, 9);
80 throw std::runtime_error(
"killing " + procName +
" was not successful!");
86 std::ifstream upTimeFile;
87 upTimeFile.open(
"/proc/uptime");
89 if (!upTimeFile.is_open()) {
93 uint64_t beforeBootTime;
94 uint64_t sysUptime = 0;
96 while (std::getline(upTimeFile, line)) {
97 sscanf(line.c_str(),
"%" PRIu64
"%" PRIu64, &sysUptime, &beforeBootTime);
111 std::exit(EXIT_SUCCESS);
114 std::exit(EXIT_FAILURE);
117 std::signal(SIGCHLD, SIG_IGN);
118 std::signal(SIGHUP, SIG_IGN);
122 std::exit(EXIT_FAILURE);
125 std::exit(EXIT_SUCCESS);
128 auto retval = chdir(
"/test");
133 for (
int x = sysconf(_SC_OPEN_MAX); x >= 0; x--) {
142 if (!statvfs(absoluteFilePath.c_str(), &buf)) {
143 uint64_t blksize, blocks, freeblks, disk_size, used, free;
144 std::cout <<
"blksize :" << buf.f_bsize << std::endl;
145 std::cout <<
"blocks : " << buf.f_blocks;
146 std::cout <<
"bfree : " << buf.f_bfree;
147 std::cout <<
"bavail: " << buf.f_bavail;
148 std::cout <<
"f_frsize: " << buf.f_frsize;
149 blksize = buf.f_bsize;
150 blocks = buf.f_blocks;
151 freeblks = buf.f_bfree;
152 disk_size = blocks * blksize;
153 free = freeblks * blksize;
154 used = disk_size - free;
156 std::cout <<
"disk " << absoluteFilePath
157 <<
" disksize: " << disk_size
170 struct passwd *pw = getpwuid(getuid());
171 if (
nullptr != pw && 0 == statvfs(pw->pw_dir, &stat)) {
172 std::cout <<
"path " << pw->pw_dir << std::endl;
173 uint64_t freeBytes = stat.f_bavail * stat.f_frsize;
180 std::ifstream versionFile;
181 versionFile.open(
"/proc/version_signature");
183 if (!versionFile.is_open()) {
184 return std::string();
187 std::getline(versionFile, line);
194 std::ifstream versionFile;
195 versionFile.open(
"/proc/version");
197 if (!versionFile.is_open()) {
198 return std::string();
201 std::getline(versionFile, line);
208 const std::string processPrefix = {
"ping -c 1 -w 1 "};
209 const std::string processPostfix = {
" 2>&1"};
210 auto fd = popen((processPrefix + address + processPostfix).c_str(),
"r");
211 std::this_thread::sleep_for(std::chrono::seconds(2));
217 size_t sz =
sizeof(buff);
218 while (getline(&ptr, &sz, fd) != -1) {
219 std::string line(buff);
220 if (line.find(
" 1 received") != std::string::npos) {
224 if (line.find(
"100% packet loss") != std::string::npos) {
233 uint32_t Threads = 0;
234 std::ifstream memoryFile;
235 memoryFile.open(
"/proc/self/status");
237 while (std::getline(memoryFile, line)) {
238 sscanf(line.c_str(),
"Threads: %u", &Threads);
244 uint32_t Threads = 0;
245 std::ifstream memoryFile;
248 while (std::getline(memoryFile, line)) {
249 sscanf(line.c_str(),
"Threads: %u", &Threads);
255 const std::string sysClassPath =
"/sys/class/net/";
257 std::ifstream IFaceFile;
258 IFaceFile.open(sysClassPath + deviceName +
"/address");
260 std::getline(IFaceFile, line);