SlideShare a Scribd company logo
1 of 21
Download to read offline
Need help implementing the skeleton code below, I have provided the main.cpp that was given,
so no changes needed to be done there. Some guide lines given in the attached image.
The /proc directory is a pseudo filesystem that allows access to kernel data structures
while in user space. It allows you to view some of the information the kernel keeps on
running processes. To view information about a specific process you just need to view files
inside of the directory: /proc/[pid]. For more information simply view the manpage with
man proc.
Skeleton Code: Implement this using C++
[Code]
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/* ------------------------------------------------------------------------- */
/****User Defined Includes *****/
/* ------------------------------------------------------------------------- */
#include "proctest.h"
/* ------------------------------------------------------------------------- */
/* Proctest Private Member Functions */
/* ------------------------------------------------------------------------- */
/*
* This function turns a char* buffer into a string given the address
* to the buffer.
*/
std::string Proctest::stringify_buffer(char *buffer)
{
std::string buffer_string = "";
int pos = 0;
while(true)
{
if(buffer[pos] == '0')
{
break;
}
else
{
buffer_string += buffer[pos];
pos++;
}
}
return buffer_string;
}
/*
* This function takes in a string and breaks it up into a vector
* of space separated words.
*/
std::vector Proctest::split_on_spaces(std::string input)
{
std::vector components;
std::string token = "";
for(unsigned short int i=0; i {
if(input[i] != ' ')
{
token += input[i];
}
else
{
components.push_back(token);
token = "";
}
}
return components;
}
-------------------------------------------------------------------------
/***** Proctest Public Member Functions *****/
-----------------------------------------------------------------------
Proctest::Proctest(int process_id)
{
/* Record process ID */
/* Initialize the read buffer */
/* Read from the stat file */
/* Read from the status file */
/* Find the number of open file descriptors by counting /proc/[pid]/fd */
/* Read Memory Map */
}
Proctest::~Proctest()
{
// Free buffer memory & clear all vectors
}
std::string Proctest::getpid()
{
return "";
}
std::string Proctest::getppid()
{
return "";
}
std::string Proctest::geteuid()
{
return "";
}
std::string Proctest::getegid()
{
return "";
}
std::string Proctest::getruid()
{
return "";
}
std::string Proctest::getrgid()
{
return "";
}
std::string Proctest::getfsuid()
{
return "";
}
std::string Proctest::getfsgid()
{
return "";
}
std::string Proctest::getstate()
{
return "";
}
std::string Proctest::getthread_count()
{
return "";
}
std::string Proctest::getpriority()
{
return "";
}
std::string Proctest::getniceness()
{
return "";
}
std::string Proctest::getstime()
{
return "";
}
std::string Proctest::getutime()
{
return "";
}
std::string Proctest::getcstime()
{
return "";
}
std::string Proctest::getcutime()
{
return "";
}
std::string Proctest::getwwcode()
{
return "";
}
std::string Proctest::getendcode()
{
return "";
}
std::string Proctest::getesp()
{
return "";
}
std::string Proctest::geteip()
{
return "";
}
std::string Proctest::getfiles()
{
return "";
}
std::string Proctest::getvoluntary_context_switches()
{
return "";
}
std::string Proctest::getnonvoluntary_context_switches()
{
return "";
}
std::string Proctest::getlast_cpu()
{
return "";
}
std::string Proctest::getallowed_cpus()
{
return "";
}
std::vector Proctest::getmemory_map()
{
return std::vector();
}
[/EndCode]
Main.cpp given: Nothing to change here.
[Code]
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/* ------------------------------------------------------------------------- */
/* User Defined */
/* ------------------------------------------------------------------------- */
#include "proctest.h"
int main()
{
/* Read in PID */
int pid;
std::cout << "Enter the pid of a process: ";
std::cin >> pid;
while(std::cin.fail())
{
std::cout << "[ERROR]: PID is not an integer. Try again: ";
std::cin >> pid;
}
/* Check a process with that pid actually exists in the system */
std::string fname = "";
while(true)
{
fname = "/proc/" + std::to_string(pid) + "/stat";
struct stat test_buffer;
if(stat(fname.c_str(), &test_buffer) != 0)
{
std::cout << "Process does not exist. Try again: ";
std::cin >> pid;
while(std::cin.fail())
{
std::cout << "[ERROR]: PID is not an integer. Try again: ";
std::cin >> pid;
}
}
else
{
break;
}
}
Proctest *process_data = new Proctest(pid);
/* Print everything */
std::cout << "Process Information: " << std::endl;
std::cout << " 1) Identifiers" << std::endl;
std::cout << " PID: " << process_data->getpid() << std::endl;
std::cout << " PPID: " << process_data->getppid() << std::endl;
std::cout << " EUID: " << process_data->geteuid() << std::endl;
std::cout << " EGID: " << process_data->getegid() << std::endl;
std::cout << " RUID: " << process_data->getruid() << std::endl;
std::cout << " RGID: " << process_data->getrgid() << std::endl;
std::cout << " FSUID: " << process_data->getfsuid() << std::endl;
std::cout << " FSGID: " << process_data->getfsgid() << std::endl;
std::cout << std::endl;
std::cout << " 2) State" << std::endl;
std::cout << " State: " << process_data->getstate() << std::endl;
std::cout << std::endl;
std::cout << " 3) Thread Information" << std::endl;
std::cout << " Thread Count: " << process_data->getthread_count() << std::endl;
std::cout << std::endl;
std::cout << " 4) Priority" << std::endl;
std::cout << " Priority Number: " << process_data->getpriority() << std::endl;
std::cout << " Niceness Value: " << process_data->getniceness() << std::endl;
std::cout << std::endl;
std::cout << " 5) Time Information" << std::endl;
std::cout << " stime: " << process_data->getstime() << std::endl;
std::cout << " utime: " << process_data->getutime() << std::endl;
std::cout << " cstime: " << process_data->getcstime() << std::endl;
std::cout << " cutime: " << process_data->getcutime() << std::endl;
std::cout << std::endl;
std::cout << " 6) Address Space" << std::endl;
std::cout << " Startcode: " << process_data->getstartcode() << std::endl;
std::cout << " Endcode: " << process_data->getendcode() << std::endl;
std::cout << " ESP: " << process_data->getesp() << std::endl;
std::cout << " EIP: " << process_data->geteip() << std::endl;
std::cout << std::endl;
std::cout << " 7) Resources" << std::endl;
std::cout << " File Handles: " << process_data->getfiles() << std::endl;
std::cout << " Voluntary Context Switches: " << process_data-
>getvoluntary_context_switches() << std::endl;
std::cout << " Nonvoluntary Context Switches: " << process_data-
>getnonvoluntary_context_switches() << std::endl;
std::cout << std::endl;
std::cout << " 8) Processor" << std::endl;
std::cout << " Last Processor: " << process_data->getlast_cpu() << std::endl;
std::cout << " Allowed Cores: " << process_data->getallowed_cpus() << std::endl;
std::cout << std::endl;
std::cout << " 9) Memory" << std::endl;
std::vector temp_mem_array = process_data->getmemory_map();
for(unsigned short int i=0; i {
std::cout << " " << temp_mem_array[i] << std::endl;
}
return 0;
}
[EndMain.cpp]
Header File:
[Code]
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
class Proctest
{
private:
int m_process_id;
char *m_read_buffer;
std::string m_num_fds;
std::vector m_stat_array;
std::vector > m_status_array;
std::vector m_mem_array;
std::string stringify_buffer(char *buffer);
std::vector split_on_spaces(std::string input);
public:
/* Constructor */
Proctest(int process_id);
~Proctest();
/* Process IDs */
std::string getpid();
std::string getppid();
std::string geteuid();
std::string getegid();
std::string getruid();
std::string getrgid();
std::string getfsuid();
std::string getfsgid();
/* State */
std::string getstate();
/* Thread Information */
std::string getthread_count();
/* Scheduling Information */
std::string getpriority();
std::string getniceness();
/* Time Information */
std::string getstime();
std::string getutime();
std::string getcstime();
std::string getcutime();
/* Address Space */
std::string getstartcode();
std::string getendcode();
std::string getesp();
std::string geteip();
/* Resources */
std::string getfiles();
std::string getvoluntary_context_switches();
std::string getnonvoluntary_context_switches();
/* Processor Information */
std::string getlast_cpu();
std::string getallowed_cpus();
/* Memory */
std::vector getmemory_map();
};
[EndCode] Using the files stored at /proc write a program/script to find information about a
specific process using a user provided pid. In the following, you will find a list of the task struct
members for which you are required to find their value In the task.struct a lot of the data you are
finding is not represented as member values but instead pointers to other linux data structures
that contain these members. All of the information you will be retrieving can be found in a
processs proc directory (/proc/Ipid). Your program must be able to retrieve the following data
about any given process if the given process Id is existing under direcotry /proc Table #1:
Process Attributes Category Required Variables/Items Description Identifiers PID. PPID Process
ID of the current process and its parent EUID, EGID Effective user and group ID RUIDO, RGID
Real user and group ID FSUID, FSGID File system user and group ID State D, T, Z. X Running,
Sleeping, Disk sleeping, Stopped Zombie, and Dead Thread Info Thread IDs of a process
Information Priority Priority Number Integer value from 1 to 99 for real time processes Niceness
Value Integer value from -20 to 19 Time Time that a process has been scheduled stime ultime in
kernel r mode Information & cu time Time that a process has waited on children. cstime being
run in kernel /user mode Startcode & Endcode The start and end of a process in memory
Resources File Handles & Number of fds used, and number of voluntary/involuntary context
switches Context Switches Which cores the process is allowed to run on and which one was last
used Address range, permissions Output a file containing the process's Memory Map offset, dev
inode. currently mappped memory regions and path name
Solution
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/* ------------------------------------------------------------------------- */
/****User Defined Includes *****/
/* ------------------------------------------------------------------------- */
#include "proctest.h"
/* ------------------------------------------------------------------------- */
/* Proctest Private Member Functions */
/* ------------------------------------------------------------------------- */
/*
* This function turns a char* buffer into a string given the address
* to the buffer.
*/
std::string Proctest::stringify_buffer(char *buffer)
{
std::string buffer_string = "";
int pos = 0;
while(true)
{
if(buffer[pos] == '0')
{
break;
}
else
{
buffer_string += buffer[pos];
pos++;
}
}
return buffer_string;
}
/*
* This function takes in a string and breaks it up into a vector
* of space separated words.
*/
std::vector Proctest::split_on_spaces(std::string input)
{
std::vector components;
std::string token = "";
for(unsigned short int i=0; i {
if(input[i] != ' ')
{
token += input[i];
}
else
{
components.push_back(token);
token = "";
}
}
return components;
}
-------------------------------------------------------------------------
/***** Proctest Public Member Functions *****/
-----------------------------------------------------------------------
Proctest::Proctest(int process_id)
{
/* Record process ID */
/* Initialize the read buffer */
/* Read from the stat file */
/* Read from the status file */
/* Find the number of open file descriptors by counting /proc/[pid]/fd */
/* Read Memory Map */
}
Proctest::~Proctest()
{
// Free buffer memory & clear all vectors
}
std::string Proctest::getpid()
{
return "";
}
std::string Proctest::getppid()
{
return "";
}
std::string Proctest::geteuid()
{
return "";
}
std::string Proctest::getegid()
{
return "";
}
std::string Proctest::getruid()
{
return "";
}
std::string Proctest::getrgid()
{
return "";
}
std::string Proctest::getfsuid()
{
return "";
}
std::string Proctest::getfsgid()
{
return "";
}
std::string Proctest::getstate()
{
return "";
}
std::string Proctest::getthread_count()
{
return "";
}
std::string Proctest::getpriority()
{
return "";
}
std::string Proctest::getniceness()
{
return "";
}
std::string Proctest::getstime()
{
return "";
}
std::string Proctest::getutime()
{
return "";
}
std::string Proctest::getcstime()
{
return "";
}
std::string Proctest::getcutime()
{
return "";
}
std::string Proctest::getwwcode()
{
return "";
}
std::string Proctest::getendcode()
{
return "";
}
std::string Proctest::getesp()
{
return "";
}
std::string Proctest::geteip()
{
return "";
}
std::string Proctest::getfiles()
{
return "";
}
std::string Proctest::getvoluntary_context_switches()
{
return "";
}
std::string Proctest::getnonvoluntary_context_switches()
{
return "";
}
std::string Proctest::getlast_cpu()
{
return "";
}
std::string Proctest::getallowed_cpus()
{
return "";
}
std::vector Proctest::getmemory_map()
{
return std::vector();
}
[/EndCode]
Main.cpp given: Nothing to change here.
[Code]
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/* ------------------------------------------------------------------------- */
/* User Defined */
/* ------------------------------------------------------------------------- */
#include "proctest.h"
int main()
{
/* Read in PID */
int pid;
std::cout << "Enter the pid of a process: ";
std::cin >> pid;
while(std::cin.fail())
{
std::cout << "[ERROR]: PID is not an integer. Try again: ";
std::cin >> pid;
}
/* Check a process with that pid actually exists in the system */
std::string fname = "";
while(true)
{
fname = "/proc/" + std::to_string(pid) + "/stat";
struct stat test_buffer;
if(stat(fname.c_str(), &test_buffer) != 0)
{
std::cout << "Process does not exist. Try again: ";
std::cin >> pid;
while(std::cin.fail())
{
std::cout << "[ERROR]: PID is not an integer. Try again: ";
std::cin >> pid;
}
}
else
{
break;
}
}
Proctest *process_data = new Proctest(pid);
/* Print everything */
std::cout << "Process Information: " << std::endl;
std::cout << " 1) Identifiers" << std::endl;
std::cout << " PID: " << process_data->getpid() << std::endl;
std::cout << " PPID: " << process_data->getppid() << std::endl;
std::cout << " EUID: " << process_data->geteuid() << std::endl;
std::cout << " EGID: " << process_data->getegid() << std::endl;
std::cout << " RUID: " << process_data->getruid() << std::endl;
std::cout << " RGID: " << process_data->getrgid() << std::endl;
std::cout << " FSUID: " << process_data->getfsuid() << std::endl;
std::cout << " FSGID: " << process_data->getfsgid() << std::endl;
std::cout << std::endl;
std::cout << " 2) State" << std::endl;
std::cout << " State: " << process_data->getstate() << std::endl;
std::cout << std::endl;
std::cout << " 3) Thread Information" << std::endl;
std::cout << " Thread Count: " << process_data->getthread_count() << std::endl;
std::cout << std::endl;
std::cout << " 4) Priority" << std::endl;
std::cout << " Priority Number: " << process_data->getpriority() << std::endl;
std::cout << " Niceness Value: " << process_data->getniceness() << std::endl;
std::cout << std::endl;
std::cout << " 5) Time Information" << std::endl;
std::cout << " stime: " << process_data->getstime() << std::endl;
std::cout << " utime: " << process_data->getutime() << std::endl;
std::cout << " cstime: " << process_data->getcstime() << std::endl;
std::cout << " cutime: " << process_data->getcutime() << std::endl;
std::cout << std::endl;
std::cout << " 6) Address Space" << std::endl;
std::cout << " Startcode: " << process_data->getstartcode() << std::endl;
std::cout << " Endcode: " << process_data->getendcode() << std::endl;
std::cout << " ESP: " << process_data->getesp() << std::endl;
std::cout << " EIP: " << process_data->geteip() << std::endl;
std::cout << std::endl;
std::cout << " 7) Resources" << std::endl;
std::cout << " File Handles: " << process_data->getfiles() << std::endl;
std::cout << " Voluntary Context Switches: " << process_data-
>getvoluntary_context_switches() << std::endl;
std::cout << " Nonvoluntary Context Switches: " << process_data-
>getnonvoluntary_context_switches() << std::endl;
std::cout << std::endl;
std::cout << " 8) Processor" << std::endl;
std::cout << " Last Processor: " << process_data->getlast_cpu() << std::endl;
std::cout << " Allowed Cores: " << process_data->getallowed_cpus() << std::endl;
std::cout << std::endl;
std::cout << " 9) Memory" << std::endl;
std::vector temp_mem_array = process_data->getmemory_map();
for(unsigned short int i=0; i {
std::cout << " " << temp_mem_array[i] << std::endl;
}
return 0;
}
[EndMain.cpp]
Header File:
[Code]
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
class Proctest
{
private:
int m_process_id;
char *m_read_buffer;
std::string m_num_fds;
std::vector m_stat_array;
std::vector > m_status_array;
std::vector m_mem_array;
std::string stringify_buffer(char *buffer);
std::vector split_on_spaces(std::string input);
public:
/* Constructor */
Proctest(int process_id);
~Proctest();
/* Process IDs */
std::string getpid();
std::string getppid();
std::string geteuid();
std::string getegid();
std::string getruid();
std::string getrgid();
std::string getfsuid();
std::string getfsgid();
/* State */
std::string getstate();
/* Thread Information */
std::string getthread_count();
/* Scheduling Information */
std::string getpriority();
std::string getniceness();
/* Time Information */
std::string getstime();
std::string getutime();
std::string getcstime();
std::string getcutime();
/* Address Space */
std::string getstartcode();
std::string getendcode();
std::string getesp();
std::string geteip();
/* Resources */
std::string getfiles();
std::string getvoluntary_context_switches();
std::string getnonvoluntary_context_switches();
/* Processor Information */
std::string getlast_cpu();
std::string getallowed_cpus();
/* Memory */
std::vector getmemory_map();
};

More Related Content

Similar to Need help implementing the skeleton code below, I have provided the .pdf

File encryption. [32] Write a program which accepts a filename as a .pdf
File encryption. [32] Write a program which accepts a filename as a .pdfFile encryption. [32] Write a program which accepts a filename as a .pdf
File encryption. [32] Write a program which accepts a filename as a .pdf
jyothimuppasani1
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
Yandex
 
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
gertrudebellgrove
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8
PrinceGuru MS
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
Remy Sharp
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
PL dream
 

Similar to Need help implementing the skeleton code below, I have provided the .pdf (20)

Simple API for XML
Simple API for XMLSimple API for XML
Simple API for XML
 
JUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by exampleJUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by example
 
computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)
 
rrxv6 Build a Riscv xv6 Kernel in Rust.pdf
rrxv6 Build a Riscv xv6 Kernel in Rust.pdfrrxv6 Build a Riscv xv6 Kernel in Rust.pdf
rrxv6 Build a Riscv xv6 Kernel in Rust.pdf
 
A22 Introduction to DTrace by Kyle Hailey
A22 Introduction to DTrace by Kyle HaileyA22 Introduction to DTrace by Kyle Hailey
A22 Introduction to DTrace by Kyle Hailey
 
File encryption. [32] Write a program which accepts a filename as a .pdf
File encryption. [32] Write a program which accepts a filename as a .pdfFile encryption. [32] Write a program which accepts a filename as a .pdf
File encryption. [32] Write a program which accepts a filename as a .pdf
 
Ganglia Monitoring Tool
Ganglia Monitoring ToolGanglia Monitoring Tool
Ganglia Monitoring Tool
 
Pycon - Python for ethical hackers
Pycon - Python for ethical hackers Pycon - Python for ethical hackers
Pycon - Python for ethical hackers
 
Improving go-git performance
Improving go-git performanceImproving go-git performance
Improving go-git performance
 
Source Code of Building Linux IPv6 DNS Server (Complete Sourcecode)
Source Code of Building Linux IPv6 DNS Server (Complete Sourcecode)Source Code of Building Linux IPv6 DNS Server (Complete Sourcecode)
Source Code of Building Linux IPv6 DNS Server (Complete Sourcecode)
 
Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
 
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
 
CGI.ppt
CGI.pptCGI.ppt
CGI.ppt
 
Core Php Component Presentation
Core Php Component PresentationCore Php Component Presentation
Core Php Component Presentation
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
 
HSA Kernel Code (KFD v0.6)
HSA Kernel Code (KFD v0.6)HSA Kernel Code (KFD v0.6)
HSA Kernel Code (KFD v0.6)
 
High Performance tDiary
High Performance tDiaryHigh Performance tDiary
High Performance tDiary
 

More from ezzi552

Consider the language L = { anb2n n 0 }.Give an implementation.pdf
Consider the language L = { anb2n  n  0 }.Give an implementation.pdfConsider the language L = { anb2n  n  0 }.Give an implementation.pdf
Consider the language L = { anb2n n 0 }.Give an implementation.pdf
ezzi552
 
Case Study.You are the Chair of the Department of Surgery at a lar.pdf
Case Study.You are the Chair of the Department of Surgery at a lar.pdfCase Study.You are the Chair of the Department of Surgery at a lar.pdf
Case Study.You are the Chair of the Department of Surgery at a lar.pdf
ezzi552
 
1)Using general mass-media (such as news sites) identify a recent co.pdf
1)Using general mass-media (such as news sites) identify a recent co.pdf1)Using general mass-media (such as news sites) identify a recent co.pdf
1)Using general mass-media (such as news sites) identify a recent co.pdf
ezzi552
 
What is not true about the membranes of prokaryotic organism a. The.pdf
What is not true about the membranes of prokaryotic organism  a. The.pdfWhat is not true about the membranes of prokaryotic organism  a. The.pdf
What is not true about the membranes of prokaryotic organism a. The.pdf
ezzi552
 
Based on the elements from the Ruby Payne readings create a resource.pdf
Based on the elements from the Ruby Payne readings create a resource.pdfBased on the elements from the Ruby Payne readings create a resource.pdf
Based on the elements from the Ruby Payne readings create a resource.pdf
ezzi552
 

More from ezzi552 (20)

Execute the following code and identify the errors in the program. D.pdf
Execute the following code and identify the errors in the program. D.pdfExecute the following code and identify the errors in the program. D.pdf
Execute the following code and identify the errors in the program. D.pdf
 
Essay question The genomes of lots and lots of organisms (mostly ba.pdf
Essay question The genomes of lots and lots of organisms (mostly ba.pdfEssay question The genomes of lots and lots of organisms (mostly ba.pdf
Essay question The genomes of lots and lots of organisms (mostly ba.pdf
 
Consider the language L = { anb2n n 0 }.Give an implementation.pdf
Consider the language L = { anb2n  n  0 }.Give an implementation.pdfConsider the language L = { anb2n  n  0 }.Give an implementation.pdf
Consider the language L = { anb2n n 0 }.Give an implementation.pdf
 
Case Study.You are the Chair of the Department of Surgery at a lar.pdf
Case Study.You are the Chair of the Department of Surgery at a lar.pdfCase Study.You are the Chair of the Department of Surgery at a lar.pdf
Case Study.You are the Chair of the Department of Surgery at a lar.pdf
 
An Unsorted Type ADT is to be extended by the addition of function S.pdf
An Unsorted Type ADT is to be extended by the addition of function S.pdfAn Unsorted Type ADT is to be extended by the addition of function S.pdf
An Unsorted Type ADT is to be extended by the addition of function S.pdf
 
alue 0.83 points M7-6 Calculating Cost of Goods Available for Sale, E.pdf
alue 0.83 points M7-6 Calculating Cost of Goods Available for Sale, E.pdfalue 0.83 points M7-6 Calculating Cost of Goods Available for Sale, E.pdf
alue 0.83 points M7-6 Calculating Cost of Goods Available for Sale, E.pdf
 
1)Using general mass-media (such as news sites) identify a recent co.pdf
1)Using general mass-media (such as news sites) identify a recent co.pdf1)Using general mass-media (such as news sites) identify a recent co.pdf
1)Using general mass-media (such as news sites) identify a recent co.pdf
 
1. The notion that two network exist in the brain, one for emotional.pdf
1. The notion that two network exist in the brain, one for emotional.pdf1. The notion that two network exist in the brain, one for emotional.pdf
1. The notion that two network exist in the brain, one for emotional.pdf
 
Which of the following is a bank liabilityA. Reserve deposits at .pdf
Which of the following is a bank liabilityA. Reserve deposits at .pdfWhich of the following is a bank liabilityA. Reserve deposits at .pdf
Which of the following is a bank liabilityA. Reserve deposits at .pdf
 
What was Eisenhower’s reinsurance plan What was Eisenhower’s r.pdf
What was Eisenhower’s reinsurance plan What was Eisenhower’s r.pdfWhat was Eisenhower’s reinsurance plan What was Eisenhower’s r.pdf
What was Eisenhower’s reinsurance plan What was Eisenhower’s r.pdf
 
What does the following program do What’s its time complexity Just.pdf
What does the following program do What’s its time complexity Just.pdfWhat does the following program do What’s its time complexity Just.pdf
What does the following program do What’s its time complexity Just.pdf
 
What is not true about the membranes of prokaryotic organism a. The.pdf
What is not true about the membranes of prokaryotic organism  a. The.pdfWhat is not true about the membranes of prokaryotic organism  a. The.pdf
What is not true about the membranes of prokaryotic organism a. The.pdf
 
What behavior characteristics are associated with each of the four s.pdf
What behavior characteristics are associated with each of the four s.pdfWhat behavior characteristics are associated with each of the four s.pdf
What behavior characteristics are associated with each of the four s.pdf
 
What are someways to better understand accounting There is a lot of.pdf
What are someways to better understand accounting There is a lot of.pdfWhat are someways to better understand accounting There is a lot of.pdf
What are someways to better understand accounting There is a lot of.pdf
 
Based on the elements from the Ruby Payne readings create a resource.pdf
Based on the elements from the Ruby Payne readings create a resource.pdfBased on the elements from the Ruby Payne readings create a resource.pdf
Based on the elements from the Ruby Payne readings create a resource.pdf
 
The answer has to be original.For this week’s discussion, complete.pdf
The answer has to be original.For this week’s discussion, complete.pdfThe answer has to be original.For this week’s discussion, complete.pdf
The answer has to be original.For this week’s discussion, complete.pdf
 
Assume you have a scanner object (called input).Declare an integer.pdf
Assume you have a scanner object (called input).Declare an integer.pdfAssume you have a scanner object (called input).Declare an integer.pdf
Assume you have a scanner object (called input).Declare an integer.pdf
 
6. Establishing priorities is an issue that local governments strugg.pdf
6. Establishing priorities is an issue that local governments strugg.pdf6. Establishing priorities is an issue that local governments strugg.pdf
6. Establishing priorities is an issue that local governments strugg.pdf
 
Suppose that A and B are attributes of a certain relational table. G.pdf
Suppose that A and B are attributes of a certain relational table. G.pdfSuppose that A and B are attributes of a certain relational table. G.pdf
Suppose that A and B are attributes of a certain relational table. G.pdf
 
RHCE is least associated with which Rh group (D--, R1r, Ror, Rzy) .pdf
RHCE is least associated with which Rh group (D--, R1r, Ror, Rzy) .pdfRHCE is least associated with which Rh group (D--, R1r, Ror, Rzy) .pdf
RHCE is least associated with which Rh group (D--, R1r, Ror, Rzy) .pdf
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 

Need help implementing the skeleton code below, I have provided the .pdf

  • 1. Need help implementing the skeleton code below, I have provided the main.cpp that was given, so no changes needed to be done there. Some guide lines given in the attached image. The /proc directory is a pseudo filesystem that allows access to kernel data structures while in user space. It allows you to view some of the information the kernel keeps on running processes. To view information about a specific process you just need to view files inside of the directory: /proc/[pid]. For more information simply view the manpage with man proc. Skeleton Code: Implement this using C++ [Code] #include #include #include #include #include #include #include #include #include #include #include #include /* ------------------------------------------------------------------------- */ /****User Defined Includes *****/ /* ------------------------------------------------------------------------- */ #include "proctest.h" /* ------------------------------------------------------------------------- */ /* Proctest Private Member Functions */ /* ------------------------------------------------------------------------- */ /* * This function turns a char* buffer into a string given the address * to the buffer. */ std::string Proctest::stringify_buffer(char *buffer) { std::string buffer_string = "";
  • 2. int pos = 0; while(true) { if(buffer[pos] == '0') { break; } else { buffer_string += buffer[pos]; pos++; } } return buffer_string; } /* * This function takes in a string and breaks it up into a vector * of space separated words. */ std::vector Proctest::split_on_spaces(std::string input) { std::vector components; std::string token = ""; for(unsigned short int i=0; i { if(input[i] != ' ') { token += input[i]; } else { components.push_back(token); token = ""; } } return components; }
  • 3. ------------------------------------------------------------------------- /***** Proctest Public Member Functions *****/ ----------------------------------------------------------------------- Proctest::Proctest(int process_id) { /* Record process ID */ /* Initialize the read buffer */ /* Read from the stat file */ /* Read from the status file */ /* Find the number of open file descriptors by counting /proc/[pid]/fd */ /* Read Memory Map */ } Proctest::~Proctest() { // Free buffer memory & clear all vectors } std::string Proctest::getpid() { return ""; } std::string Proctest::getppid() { return ""; } std::string Proctest::geteuid() { return ""; } std::string Proctest::getegid() { return ""; } std::string Proctest::getruid()
  • 4. { return ""; } std::string Proctest::getrgid() { return ""; } std::string Proctest::getfsuid() { return ""; } std::string Proctest::getfsgid() { return ""; } std::string Proctest::getstate() { return ""; } std::string Proctest::getthread_count() { return ""; } std::string Proctest::getpriority() { return ""; } std::string Proctest::getniceness() { return ""; } std::string Proctest::getstime() { return ""; } std::string Proctest::getutime()
  • 5. { return ""; } std::string Proctest::getcstime() { return ""; } std::string Proctest::getcutime() { return ""; } std::string Proctest::getwwcode() { return ""; } std::string Proctest::getendcode() { return ""; } std::string Proctest::getesp() { return ""; } std::string Proctest::geteip() { return ""; } std::string Proctest::getfiles() { return ""; } std::string Proctest::getvoluntary_context_switches() { return ""; } std::string Proctest::getnonvoluntary_context_switches()
  • 6. { return ""; } std::string Proctest::getlast_cpu() { return ""; } std::string Proctest::getallowed_cpus() { return ""; } std::vector Proctest::getmemory_map() { return std::vector(); } [/EndCode] Main.cpp given: Nothing to change here. [Code] #include #include #include #include #include #include #include #include #include #include #include #include /* ------------------------------------------------------------------------- */ /* User Defined */ /* ------------------------------------------------------------------------- */ #include "proctest.h" int main()
  • 7. { /* Read in PID */ int pid; std::cout << "Enter the pid of a process: "; std::cin >> pid; while(std::cin.fail()) { std::cout << "[ERROR]: PID is not an integer. Try again: "; std::cin >> pid; } /* Check a process with that pid actually exists in the system */ std::string fname = ""; while(true) { fname = "/proc/" + std::to_string(pid) + "/stat"; struct stat test_buffer; if(stat(fname.c_str(), &test_buffer) != 0) { std::cout << "Process does not exist. Try again: "; std::cin >> pid; while(std::cin.fail()) { std::cout << "[ERROR]: PID is not an integer. Try again: "; std::cin >> pid; } } else { break; } } Proctest *process_data = new Proctest(pid); /* Print everything */ std::cout << "Process Information: " << std::endl; std::cout << " 1) Identifiers" << std::endl;
  • 8. std::cout << " PID: " << process_data->getpid() << std::endl; std::cout << " PPID: " << process_data->getppid() << std::endl; std::cout << " EUID: " << process_data->geteuid() << std::endl; std::cout << " EGID: " << process_data->getegid() << std::endl; std::cout << " RUID: " << process_data->getruid() << std::endl; std::cout << " RGID: " << process_data->getrgid() << std::endl; std::cout << " FSUID: " << process_data->getfsuid() << std::endl; std::cout << " FSGID: " << process_data->getfsgid() << std::endl; std::cout << std::endl; std::cout << " 2) State" << std::endl; std::cout << " State: " << process_data->getstate() << std::endl; std::cout << std::endl; std::cout << " 3) Thread Information" << std::endl; std::cout << " Thread Count: " << process_data->getthread_count() << std::endl; std::cout << std::endl; std::cout << " 4) Priority" << std::endl; std::cout << " Priority Number: " << process_data->getpriority() << std::endl; std::cout << " Niceness Value: " << process_data->getniceness() << std::endl; std::cout << std::endl; std::cout << " 5) Time Information" << std::endl; std::cout << " stime: " << process_data->getstime() << std::endl; std::cout << " utime: " << process_data->getutime() << std::endl; std::cout << " cstime: " << process_data->getcstime() << std::endl; std::cout << " cutime: " << process_data->getcutime() << std::endl; std::cout << std::endl; std::cout << " 6) Address Space" << std::endl; std::cout << " Startcode: " << process_data->getstartcode() << std::endl; std::cout << " Endcode: " << process_data->getendcode() << std::endl; std::cout << " ESP: " << process_data->getesp() << std::endl; std::cout << " EIP: " << process_data->geteip() << std::endl; std::cout << std::endl; std::cout << " 7) Resources" << std::endl; std::cout << " File Handles: " << process_data->getfiles() << std::endl; std::cout << " Voluntary Context Switches: " << process_data- >getvoluntary_context_switches() << std::endl; std::cout << " Nonvoluntary Context Switches: " << process_data-
  • 9. >getnonvoluntary_context_switches() << std::endl; std::cout << std::endl; std::cout << " 8) Processor" << std::endl; std::cout << " Last Processor: " << process_data->getlast_cpu() << std::endl; std::cout << " Allowed Cores: " << process_data->getallowed_cpus() << std::endl; std::cout << std::endl; std::cout << " 9) Memory" << std::endl; std::vector temp_mem_array = process_data->getmemory_map(); for(unsigned short int i=0; i { std::cout << " " << temp_mem_array[i] << std::endl; } return 0; } [EndMain.cpp] Header File: [Code] #include #include #include #include #include #include #include #include #include #include #include #include class Proctest { private: int m_process_id; char *m_read_buffer; std::string m_num_fds; std::vector m_stat_array;
  • 10. std::vector > m_status_array; std::vector m_mem_array; std::string stringify_buffer(char *buffer); std::vector split_on_spaces(std::string input); public: /* Constructor */ Proctest(int process_id); ~Proctest(); /* Process IDs */ std::string getpid(); std::string getppid(); std::string geteuid(); std::string getegid(); std::string getruid(); std::string getrgid(); std::string getfsuid(); std::string getfsgid(); /* State */ std::string getstate(); /* Thread Information */ std::string getthread_count(); /* Scheduling Information */ std::string getpriority(); std::string getniceness(); /* Time Information */ std::string getstime(); std::string getutime(); std::string getcstime(); std::string getcutime(); /* Address Space */ std::string getstartcode(); std::string getendcode(); std::string getesp(); std::string geteip();
  • 11. /* Resources */ std::string getfiles(); std::string getvoluntary_context_switches(); std::string getnonvoluntary_context_switches(); /* Processor Information */ std::string getlast_cpu(); std::string getallowed_cpus(); /* Memory */ std::vector getmemory_map(); }; [EndCode] Using the files stored at /proc write a program/script to find information about a specific process using a user provided pid. In the following, you will find a list of the task struct members for which you are required to find their value In the task.struct a lot of the data you are finding is not represented as member values but instead pointers to other linux data structures that contain these members. All of the information you will be retrieving can be found in a processs proc directory (/proc/Ipid). Your program must be able to retrieve the following data about any given process if the given process Id is existing under direcotry /proc Table #1: Process Attributes Category Required Variables/Items Description Identifiers PID. PPID Process ID of the current process and its parent EUID, EGID Effective user and group ID RUIDO, RGID Real user and group ID FSUID, FSGID File system user and group ID State D, T, Z. X Running, Sleeping, Disk sleeping, Stopped Zombie, and Dead Thread Info Thread IDs of a process Information Priority Priority Number Integer value from 1 to 99 for real time processes Niceness Value Integer value from -20 to 19 Time Time that a process has been scheduled stime ultime in kernel r mode Information & cu time Time that a process has waited on children. cstime being run in kernel /user mode Startcode & Endcode The start and end of a process in memory Resources File Handles & Number of fds used, and number of voluntary/involuntary context switches Context Switches Which cores the process is allowed to run on and which one was last used Address range, permissions Output a file containing the process's Memory Map offset, dev inode. currently mappped memory regions and path name Solution #include #include #include #include
  • 12. #include #include #include #include #include #include #include #include /* ------------------------------------------------------------------------- */ /****User Defined Includes *****/ /* ------------------------------------------------------------------------- */ #include "proctest.h" /* ------------------------------------------------------------------------- */ /* Proctest Private Member Functions */ /* ------------------------------------------------------------------------- */ /* * This function turns a char* buffer into a string given the address * to the buffer. */ std::string Proctest::stringify_buffer(char *buffer) { std::string buffer_string = ""; int pos = 0; while(true) { if(buffer[pos] == '0') { break; } else { buffer_string += buffer[pos]; pos++; } } return buffer_string;
  • 13. } /* * This function takes in a string and breaks it up into a vector * of space separated words. */ std::vector Proctest::split_on_spaces(std::string input) { std::vector components; std::string token = ""; for(unsigned short int i=0; i { if(input[i] != ' ') { token += input[i]; } else { components.push_back(token); token = ""; } } return components; } ------------------------------------------------------------------------- /***** Proctest Public Member Functions *****/ ----------------------------------------------------------------------- Proctest::Proctest(int process_id) { /* Record process ID */ /* Initialize the read buffer */ /* Read from the stat file */ /* Read from the status file */ /* Find the number of open file descriptors by counting /proc/[pid]/fd */ /* Read Memory Map */ } Proctest::~Proctest()
  • 14. { // Free buffer memory & clear all vectors } std::string Proctest::getpid() { return ""; } std::string Proctest::getppid() { return ""; } std::string Proctest::geteuid() { return ""; } std::string Proctest::getegid() { return ""; } std::string Proctest::getruid() { return ""; } std::string Proctest::getrgid() { return ""; } std::string Proctest::getfsuid() { return ""; } std::string Proctest::getfsgid() { return "";
  • 15. } std::string Proctest::getstate() { return ""; } std::string Proctest::getthread_count() { return ""; } std::string Proctest::getpriority() { return ""; } std::string Proctest::getniceness() { return ""; } std::string Proctest::getstime() { return ""; } std::string Proctest::getutime() { return ""; } std::string Proctest::getcstime() { return ""; } std::string Proctest::getcutime() { return ""; } std::string Proctest::getwwcode() { return "";
  • 16. } std::string Proctest::getendcode() { return ""; } std::string Proctest::getesp() { return ""; } std::string Proctest::geteip() { return ""; } std::string Proctest::getfiles() { return ""; } std::string Proctest::getvoluntary_context_switches() { return ""; } std::string Proctest::getnonvoluntary_context_switches() { return ""; } std::string Proctest::getlast_cpu() { return ""; } std::string Proctest::getallowed_cpus() { return ""; } std::vector Proctest::getmemory_map() { return std::vector();
  • 17. } [/EndCode] Main.cpp given: Nothing to change here. [Code] #include #include #include #include #include #include #include #include #include #include #include #include /* ------------------------------------------------------------------------- */ /* User Defined */ /* ------------------------------------------------------------------------- */ #include "proctest.h" int main() { /* Read in PID */ int pid; std::cout << "Enter the pid of a process: "; std::cin >> pid; while(std::cin.fail()) { std::cout << "[ERROR]: PID is not an integer. Try again: "; std::cin >> pid; } /* Check a process with that pid actually exists in the system */ std::string fname = ""; while(true)
  • 18. { fname = "/proc/" + std::to_string(pid) + "/stat"; struct stat test_buffer; if(stat(fname.c_str(), &test_buffer) != 0) { std::cout << "Process does not exist. Try again: "; std::cin >> pid; while(std::cin.fail()) { std::cout << "[ERROR]: PID is not an integer. Try again: "; std::cin >> pid; } } else { break; } } Proctest *process_data = new Proctest(pid); /* Print everything */ std::cout << "Process Information: " << std::endl; std::cout << " 1) Identifiers" << std::endl; std::cout << " PID: " << process_data->getpid() << std::endl; std::cout << " PPID: " << process_data->getppid() << std::endl; std::cout << " EUID: " << process_data->geteuid() << std::endl; std::cout << " EGID: " << process_data->getegid() << std::endl; std::cout << " RUID: " << process_data->getruid() << std::endl; std::cout << " RGID: " << process_data->getrgid() << std::endl; std::cout << " FSUID: " << process_data->getfsuid() << std::endl; std::cout << " FSGID: " << process_data->getfsgid() << std::endl; std::cout << std::endl; std::cout << " 2) State" << std::endl; std::cout << " State: " << process_data->getstate() << std::endl; std::cout << std::endl; std::cout << " 3) Thread Information" << std::endl; std::cout << " Thread Count: " << process_data->getthread_count() << std::endl;
  • 19. std::cout << std::endl; std::cout << " 4) Priority" << std::endl; std::cout << " Priority Number: " << process_data->getpriority() << std::endl; std::cout << " Niceness Value: " << process_data->getniceness() << std::endl; std::cout << std::endl; std::cout << " 5) Time Information" << std::endl; std::cout << " stime: " << process_data->getstime() << std::endl; std::cout << " utime: " << process_data->getutime() << std::endl; std::cout << " cstime: " << process_data->getcstime() << std::endl; std::cout << " cutime: " << process_data->getcutime() << std::endl; std::cout << std::endl; std::cout << " 6) Address Space" << std::endl; std::cout << " Startcode: " << process_data->getstartcode() << std::endl; std::cout << " Endcode: " << process_data->getendcode() << std::endl; std::cout << " ESP: " << process_data->getesp() << std::endl; std::cout << " EIP: " << process_data->geteip() << std::endl; std::cout << std::endl; std::cout << " 7) Resources" << std::endl; std::cout << " File Handles: " << process_data->getfiles() << std::endl; std::cout << " Voluntary Context Switches: " << process_data- >getvoluntary_context_switches() << std::endl; std::cout << " Nonvoluntary Context Switches: " << process_data- >getnonvoluntary_context_switches() << std::endl; std::cout << std::endl; std::cout << " 8) Processor" << std::endl; std::cout << " Last Processor: " << process_data->getlast_cpu() << std::endl; std::cout << " Allowed Cores: " << process_data->getallowed_cpus() << std::endl; std::cout << std::endl; std::cout << " 9) Memory" << std::endl; std::vector temp_mem_array = process_data->getmemory_map(); for(unsigned short int i=0; i { std::cout << " " << temp_mem_array[i] << std::endl; } return 0; } [EndMain.cpp]
  • 20. Header File: [Code] #include #include #include #include #include #include #include #include #include #include #include #include class Proctest { private: int m_process_id; char *m_read_buffer; std::string m_num_fds; std::vector m_stat_array; std::vector > m_status_array; std::vector m_mem_array; std::string stringify_buffer(char *buffer); std::vector split_on_spaces(std::string input); public: /* Constructor */ Proctest(int process_id); ~Proctest(); /* Process IDs */ std::string getpid(); std::string getppid(); std::string geteuid(); std::string getegid(); std::string getruid();
  • 21. std::string getrgid(); std::string getfsuid(); std::string getfsgid(); /* State */ std::string getstate(); /* Thread Information */ std::string getthread_count(); /* Scheduling Information */ std::string getpriority(); std::string getniceness(); /* Time Information */ std::string getstime(); std::string getutime(); std::string getcstime(); std::string getcutime(); /* Address Space */ std::string getstartcode(); std::string getendcode(); std::string getesp(); std::string geteip(); /* Resources */ std::string getfiles(); std::string getvoluntary_context_switches(); std::string getnonvoluntary_context_switches(); /* Processor Information */ std::string getlast_cpu(); std::string getallowed_cpus(); /* Memory */ std::vector getmemory_map(); };