Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objective The objective of this program (developed as a C++ class) is to print the full hierarchy of processes (starting with /sbin/init) for a given

image text in transcribed

image text in transcribedimage text in transcribed

Objective The objective of this program (developed as a C++ class) is to print the full hierarchy of processes (starting with /sbin/init) for a given PID (process ID, specified as a command-line argument). The data about processes is read from a given text file (as command-line argument). Background In Linux, processes are organized as a tree, rooted at /sbin/init or /lib/systemd/system which is the first process that the Linux kernel starts running. Each process is identified by a unique ID called PID (short for process ID). Furthermore, each process has a PPID (short for parent process ID). The process hierarchy can be determined manually, by recursively tracing the PPID in the output of ps -fe command. However, this program is designed to automate this task of tracing the process hierarchy. Data file formats Prior to solving any problem is important to study the supplied data. So, ensure you view the data files (yes, of course you can do this in NetBeans). The supplied data files are exactly the output of ps -fe command, also reviewed in lab exercise(s). Program requirements & Tips: This program should be developed as a C++ class with the following 2 files: O MUID hw3.h: This header file should contain the class declaration. You will need 2 public methods - O a method that loads process data from a given file into 2 unordered maps (discussed below) a method that prints the process tree for a given PID. You may add any private helper methods as you see fit. It is up to you to decide meaningful names for methods and their parameters. Each method and instance variable must be documented using Javadoc/doxygen style comments. MUID hw3.cpp: This source file should contain the implementation for the methods you have defined in the header file (ensure you #include "MUID hw3.h" in this source file). This file will also contain the implementation for the main method. Your main method should create an object and calls methods on the object with suitable parameters. To ease printing the process hierarchy, in your class use 2 unordered_maps as instance variables in your class to store the following: 1. pideppid information to ease look-up of parent process ID. 2. pidcmd information to ease look-up the command associated with a PID. Note that each process listing text file has the 1st line as a header line, which should be ignored. Use std::istringstream to process each line. Even if you don't use a specific column of data, it is still easier to read it and simply not use it. To read the full command (which has spaces in it) use std::getline method after reading specific columns. Keep I/O simple and straightforward. Note the order in which processes are printed in the sample output. It is top-down (and not bottom-up) For printing the process hierarchy in a top-down manner, you may use an iterative or a recursive solution as you see fit. However, the recursive solution will most likely be shorter than an iterative solution. Objective The objective of this program (developed as a C++ class) is to print the full hierarchy of processes (starting with /sbin/init) for a given PID (process ID, specified as a command-line argument). The data about processes is read from a given text file (as command-line argument). Background In Linux, processes are organized as a tree, rooted at /sbin/init or /lib/systemd/system which is the first process that the Linux kernel starts running. Each process is identified by a unique ID called PID (short for process ID). Furthermore, each process has a PPID (short for parent process ID). The process hierarchy can be determined manually, by recursively tracing the PPID in the output of ps -fe command. However, this program is designed to automate this task of tracing the process hierarchy. Data file formats Prior to solving any problem is important to study the supplied data. So, ensure you view the data files (yes, of course you can do this in NetBeans). The supplied data files are exactly the output of ps -fe command, also reviewed in lab exercise(s). Program requirements & Tips: This program should be developed as a C++ class with the following 2 files: O MUID hw3.h: This header file should contain the class declaration. You will need 2 public methods - O a method that loads process data from a given file into 2 unordered maps (discussed below) a method that prints the process tree for a given PID. You may add any private helper methods as you see fit. It is up to you to decide meaningful names for methods and their parameters. Each method and instance variable must be documented using Javadoc/doxygen style comments. MUID hw3.cpp: This source file should contain the implementation for the methods you have defined in the header file (ensure you #include "MUID hw3.h" in this source file). This file will also contain the implementation for the main method. Your main method should create an object and calls methods on the object with suitable parameters. To ease printing the process hierarchy, in your class use 2 unordered_maps as instance variables in your class to store the following: 1. pideppid information to ease look-up of parent process ID. 2. pidcmd information to ease look-up the command associated with a PID. Note that each process listing text file has the 1st line as a header line, which should be ignored. Use std::istringstream to process each line. Even if you don't use a specific column of data, it is still easier to read it and simply not use it. To read the full command (which has spaces in it) use std::getline method after reading specific columns. Keep I/O simple and straightforward. Note the order in which processes are printed in the sample output. It is top-down (and not bottom-up) For printing the process hierarchy in a top-down manner, you may use an iterative or a recursive solution as you see fit. However, the recursive solution will most likely be shorter than an iterative solution

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 11G SQL

Authors: Joan Casteel

2nd Edition

1133947360, 978-1133947363

More Books

Students also viewed these Databases questions