21 #include <netinet/in.h>
24 #include <sys/statvfs.h>
25 #include <sys/types.h>
31 std::ifstream temperatureFile;
32 const std::string parsePath =
"/sys/class/thermal/" + thermalZone +
"/temp";
33 temperatureFile.open(parsePath);
37 while (std::getline(temperatureFile, line))
39 auto unused = scanf(line.c_str(),
"%ld", &temperature);
42 temperatureFile.close();
50 auto dp = opendir(
"/proc");
54 while (pid < 0 && (dirp = readdir(dp)))
56 int id = atoi(dirp->d_name);
59 std::string cmdPath{
"/proc/"};
60 cmdPath.append(dirp->d_name);
61 cmdPath.append(
"/cmdline");
62 std::ifstream cmdFile(cmdPath.c_str());
64 getline(cmdFile, cmdLine);
67 size_t pos = cmdLine.find(
'\0');
68 if (pos != std::string::npos)
69 cmdLine = cmdLine.substr(0, pos);
70 pos = cmdLine.rfind(
'/');
71 if (pos != std::string::npos)
72 cmdLine = cmdLine.substr(pos + 1);
73 if (strcmp(procName.c_str(), cmdLine.c_str()) == 0)
90 throw std::runtime_error(
"Nothing to Kill, no Process " + procName +
" PID " +
93 int ret = kill(pid, 9);
96 throw std::runtime_error(
"killing " + procName +
" was not successful!");
104 std::ifstream upTimeFile;
105 upTimeFile.open(
"/proc/uptime");
107 if (!upTimeFile.is_open())
112 uint64_t beforeBootTime;
113 uint64_t sysUptime = 0;
115 while (std::getline(upTimeFile, line))
117 sscanf(line.c_str(),
"%" PRIu64
"%" PRIu64, &sysUptime, &beforeBootTime);
133 std::exit(EXIT_SUCCESS);
136 std::exit(EXIT_FAILURE);
139 std::signal(SIGCHLD, SIG_IGN);
140 std::signal(SIGHUP, SIG_IGN);
144 std::exit(EXIT_FAILURE);
147 std::exit(EXIT_SUCCESS);
150 auto retval = chdir(
"/test");
156 for (
int x = sysconf(_SC_OPEN_MAX); x >= 0; x--)
168 if (!statvfs(absoluteFilePath.c_str(), &buf))
170 uint64_t blksize, blocks, freeblks, disk_size, used, free;
171 std::cout <<
"blksize :" << buf.f_bsize << std::endl;
172 std::cout <<
"blocks : " << buf.f_blocks;
173 std::cout <<
"bfree : " << buf.f_bfree;
174 std::cout <<
"bavail: " << buf.f_bavail;
175 std::cout <<
"f_frsize: " << buf.f_frsize;
176 blksize = buf.f_bsize;
177 blocks = buf.f_blocks;
178 freeblks = buf.f_bfree;
179 disk_size = blocks * blksize;
180 free = freeblks * blksize;
181 used = disk_size - free;
183 std::cout <<
"disk " << absoluteFilePath <<
" disksize: " << disk_size <<
" free: " << free
184 <<
" used: " << used << std::endl;
198 struct passwd* pw = getpwuid(getuid());
199 if (
nullptr != pw && 0 == statvfs(pw->pw_dir, &stat))
201 std::cout <<
"path " << pw->pw_dir << std::endl;
202 uint64_t freeBytes = stat.f_bavail * stat.f_frsize;
211 std::ifstream versionFile;
212 versionFile.open(
"/proc/version_signature");
214 if (!versionFile.is_open())
216 return std::string();
219 std::getline(versionFile, line);
228 std::ifstream versionFile;
229 versionFile.open(
"/proc/version");
231 if (!versionFile.is_open())
233 return std::string();
236 std::getline(versionFile, line);
245 const std::string processPrefix = {
"ping -c 1 -w 1 "};
246 const std::string processPostfix = {
" 2>&1"};
247 auto fd = popen((processPrefix + address + processPostfix).c_str(),
"r");
248 std::this_thread::sleep_for(std::chrono::seconds(2));
255 size_t sz =
sizeof(buff);
256 while (getline(&ptr, &sz, fd) != -1)
258 std::string line(buff);
259 if (line.find(
" 1 received") != std::string::npos)
264 if (line.find(
"100% packet loss") != std::string::npos)
276 uint32_t Threads = 0;
277 std::ifstream memoryFile;
278 memoryFile.open(
"/proc/self/status");
280 while (std::getline(memoryFile, line))
282 sscanf(line.c_str(),
"Threads: %u", &Threads);
290 uint32_t Threads = 0;
291 std::ifstream memoryFile;
294 while (std::getline(memoryFile, line))
296 sscanf(line.c_str(),
"Threads: %u", &Threads);
304 const std::string sysClassPath =
"/sys/class/net/";
306 std::ifstream IFaceFile;
307 IFaceFile.open(sysClassPath + deviceName +
"/address");
309 std::getline(IFaceFile, line);