Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you will write a simple UNIX shell that accepts user commands and then executes each command in a separate process. It is

In this assignment, you will write a simple UNIX shell that accepts user commands and then executes each command in a separate process. It is based on programming project 1 in chapter 3 of the textbook. A starter skeleton program "prog.cpp" and Makefile are provided. Type make to build the executable prog2, and type ./prog2 to run it.
Read on the course website for more details and submission instructions. Complete all the required features and remove "TODO"s from the source code. It's OK to add additional helper functions but don't change the file name.
/**
* Assignment 2: Simple UNIX Shell
* @file pcbtable.h
* @author ???(TODO: your name)
* @brief This is the main function of a simple UNIX Shell. You may add additional functions in this file for your implementation
* @version 0.1
*/
// You must complete the all parts marked as "TODO". Delete "TODO" after you are done.
// Remember to add sufficient and clear comments to your code
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define MAX_LINE 80// The maximum length command
/**
* @brief parse out the command and arguments from the input command separated by spaces
*
* @param command
* @param args
* @return int
*/
int parse_command(char command[], char *args[])
{
// TODO: implement this function
}
// TODO: Add additional functions if you need
/**
* @brief The main function of a simple UNIX Shell. You may add additional functions in this file for your implementation
* @param argc The number of arguments
* @param argv The array of arguments
* @return The exit status of the program
*/
int main(int argc, char *argv[])
{
char command[MAX_LINE]; // the command that was entered
char *args[MAX_LINE /2+1]; // hold parsed out command line arguments
int should_run =1; /* flag to determine when to exit program */
// TODO: Add additional variables for the implementation.
while (should_run)
{
printf("osh>");
fflush(stdout);
// Read the input command
fgets(command, MAX_LINE, stdin);
// Parse the input command
int num_args = parse_command(command, args);
// TODO: Add your code for the implementation
/**
* After reading user input, the steps are:
*(1) fork a child process using fork()
*(2) the child process will invoke execvp()
*(3) parent will invoke wait() unless command included &
*/
}
return 0;
}

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

Database And Expert Systems Applications Dexa 2022 Workshops 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 In Computer And Information Science 33

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Alfred Taudes ,Atif Mashkoor ,Johannes Sametinger ,Jorge Martinez-Gil ,Florian Sobieczky ,Lukas Fischer ,Rudolf Ramler ,Maqbool Khan ,Gerald Czech

1st Edition

ISBN: 3031143426, 978-3031143427

More Books

Students also viewed these Databases questions

Question

Decentralization has benefits and costs. Name three of each.

Answered: 1 week ago

Question

3. Identify the methods used within each of the three approaches.

Answered: 1 week ago