This is in the UNIX operating system using the C language This assignment covers
ID: 3735213 • Letter: T
Question
This is in the UNIX operating system using the C language
This assignment covers the creation of processes using C and communicating between processes using unnamed pipes. You are to write a program that creates one child process. .On the command line, when you execute your program, I will specify the path of a single directory as the single argument to your program. each file in that directory. Your main program will spawn a child process. Your main program will examine this directory. It will need to get the status record for Your main program will open a new report file for writing. .Your main program will send file status entries, one at a time to the child process. At the end of the set of data, send the child process a status record with the inode value set to 0 so the child knows when the end of the records has beer reached. OR have the child wait for a few 5 second periods. If it receives no new buffer data after a few cycles, then time-out and complete the child tasks, exit. o o The child process will collect statistics on the files sent to it by the main program: o o o o how many regular files are there? how many directories are there? What is the total filesize in bytes? What is the total file storage allocation in blocks? .The child process will write these statistics to the report file that was opened by main. The main program will wait for the child to complete and then echo the report file'sExplanation / Answer
SYSTEM USING C LANGUAGE
WITH UNIX OPERATING SYSTEM:-
#include
#include
#include
#include
#include
#include
#include
#include
// PURPOSE: To tell the maximum value that a tree can have.
const int MAX_VALUE = 64;
// PURPOSE: To tell how many problems to do.
const int NUM_PROBLEMS = 4096;
#include "Node.h"
#include "NodeBuffer.h"
/*-------------------------------------------------------------------------*
--- ---
--- Node.h ---
--- ---
--- This file defines classes for nodes used to represent math ---
--- expressions. ---
--- ---
--- ---- ---- ---- ---- ---- ---- ---- ---- ---
--- ---
--- ---
*-------------------------------------------------------------------------*/
// PURPOSE: To distinguish among the mathematical operators.
typedef enum {
ADD_OP,
SUBTRACT_OP,
MULTIPLY_OP,
DIVIDE_OP,
NUM_OPS
}
operator_ty;
// PURPOSE: To serve as the base class for the Node classes.
class Node
{
public :
Node ()
{ }
virtual
~Node ()
{ }
virtual
double eval ()
const
= 0;
virtual
std::string toString ()
const
= 0;
};
// PURPOSE: To represent a constant.
class ConstNode : public Node
{
double constant_;
public :
ConstNode () :
Node(),
constant_((double)((rand() % MAX_VALUE) + 1) )
{ }
double eval ()
const
{ return(constant_); }
std::string toString ()
const
{
std::ostringstream stream;
stream << constant_;
return(stream.str());
}
};
// PURPOSE: To return a randomly generated Node.
extern
Node* makeNode ();
// PURPOSE: To represent an operation.
class OperatorNode : public Node
{
operator_ty operator_;
Node* lhsPtr_;
Node* rhsPtr_;
public :
OperatorNode () :
Node(),
operator_((operator_ty)(rand() % NUM_OPS)),
lhsPtr_(makeNode()),
rhsPtr_(makeNode())
{ }
~OperatorNode ()
{
delete(rhsPtr_);
delete(lhsPtr_);
}
double eval ()
const
{
double lhs = lhsPtr_->eval();
double rhs = rhsPtr_->eval();
double result;
switch (operator_)
{
case ADD_OP :
result = lhs + rhs;
break;
case SUBTRACT_OP :
result = lhs - rhs;
break;
case MULTIPLY_OP :
result = lhs * rhs;
break;
case DIVIDE_OP :
result = lhs / rhs;
break;
}
return(result);
}
std::string toString ()
const
{
std::ostringstream stream;
const char* operatorNameCPtr;
switch (operator_)
{
case ADD_OP :
operatorNameCPtr = " + ";
break;
case SUBTRACT_OP :
operatorNameCPtr = " - ";
break;
case MULTIPLY_OP :
operatorNameCPtr = " * ";
break;
case DIVIDE_OP :
operatorNameCPtr = " / ";
break;
}
stream << "(" << lhsPtr_->toString()
<< operatorNameCPtr
<< rhsPtr_->toString() << ")";
return(stream.str());
}
};
/*-------------------------------------------------------------------------*
--- ---
--- NodeBuffer.h ---
--- ---
--- This file defines a class that implements a thread-safe ---
--- buffer of pointers to math expressions. ---
--- ---
--- ---- ---- ---- ---- ---- ---- ---- ---- ---
--- ---
--- Version 1a 2018 February 22 Joseph Phillips ---
--- ---
*-------------------------------------------------------------------------*/
class NodeBuffer
{
enum { SIZE = 16 };
Node* array_[SIZE];
int inIndex_;
int outIndex_;
int numItems_;
public :
NodeBuffer ()
{
for (int i = 0; i < SIZE; i++)
{
array_[i] = NULL;
}
inIndex = outIndex = numItems_ = 0;
}
~NodeBuffer ()
{
}
int getNumItems () const
{ return(numItems_); }
void putIn (Node* nodePtr)
{
while (getNumItems() >= SIZE)
{
}
array_[inIndex_] = nodePtr;
inIndex_++;
numItems_++;
if (inIndex_ >= SIZE)
inIndex_ = 0;
}
Node* pullOut ()
{
while (getNumItems() <= 0)
{
}
Node* toReturn = array_[outIndex_];
array_[outIndex_] = NULL;
outIndex_++;
numItems_--;
if (outIndex_ >= SIZE)
outIndex_ = 0;
return(toReturn);
}
};
/*-------------------------------------------------------------------------*
--- ---
--- mathSolver.cpp ---
--- ---
--- This file defines the high-level functions of the math ---
--- generator and solver program. ---
--- ---
--- ---- ---- ---- ---- ---- ---- ---- ---- ---
--- ---
--- ---
*-------------------------------------------------------------------------*/
//
// Compile with:
// $ g++ mathSolver.cpp -o mathSolver -lpthread -g
//
#include "mathSolverHeader.h"
void evaluate (void vPtr
)
{
NodeBuffer* nodeBufferPtr = (NodeBuffer*)vPtr;
// YOUR CODE HERE
}
// PURPOSE: To return a randomly generated Node.
Node* makeNode ()
{
return( (rand() % 3) ? (Node*)new ConstNode() : (Node*)new OperatorNode() );
}
int main (int argc,
char* argv[]
)
{
NodeBuffer nodeBuffer;
pthread_t consumer0;
pthread_t consumer1;
int toReturn = EXIT_SUCCESS;
srand( (argc < 2) ? getpid() : atoi(argv[1]) );
// YOUR CODE HERE
return(toReturn);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.