Skip to content

Commit

Permalink
process
Browse files Browse the repository at this point in the history
  • Loading branch information
d0ugherty committed Aug 8, 2023
1 parent da66c65 commit aebc135
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions process.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
#include <string>
#include <iostream>
#include <fstream>
#include <sys/types.h>
#include "process.h"

Process::Process(int pid) : pid(pid) {
readStatFile();
}

void Process::readStatFile(){
std::string stat_filepath = "/proc/" + std::to_string(pid) + "/stat";
std::ifstream stat_file(stat_filepath);

if(!stat_file) {
std::cerr << "Failed to find stat file " << pid << std::endl;
return;
}

std::string line;
std::getline(stat_file, line);
stat_file.close();

std::sscanf(line.c_str(),"%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %ld %ld", &utime, &stime);
}

double Process::getCpuUsage(int pid) {
}

0 comments on commit aebc135

Please sign in to comment.