// exit
// one option
CMDTYPE getCmdType(const char *cmd)
{
if (strcmp(cmd, "exit") == 0)
return EXIT;
if (strcmp(cmd, "cd") == 0)
return CD;
if (strcmp(cmd, "pwd") == 0)
return PWD;
if (strcmp(cmd, "echo") == 0)
return ECHO;
return CMD;
}
// second option
void exit()
{
if('$1' == 'exit')
{
$2 $3;
$1;
}
else if('$3' == 'exit' )
{
$1 $2;
$2;
}
}
// pipelining
void pipes(int a, char * pipes[100], int size)
{
char* p1[10] // variable for command 1
char* p2[10] // variable for command 2
char* p3[10] // variable for command 3
int num = 0; // integer for amount of pipes
int n1 = 0; // interger for command 1 array
int n2 = 0; // integer for command 2 array
int n3 = 0; // integer for command 3 array
int status; // for status
pid_t pd, pd2, pd3; //variables for pid to be forked
for (int i=0; i<size; i++) //size of command line input
{
if(strcmp(pipes[i], "|") == 0) // if the pipe is found
{
num++; //increment the counter
}
else if(num == 0) // if no pipe found
{
p1[n1] = pipes[i]; //place the command and argument into p1
n1++; // incrementing place in command 1 array
}
else if(num == 1) // if 1 pipe is found
{
p2[n2] = pipes[i]; //place the command and argumemnt into p2
n2++; //increment place in command 2 array
}
else if (num == 2) // if 2 pipes are found
{
p3[n3] = pipes[i]; //place the command and argumemnt into p3
n3++; //increment place in command 3 array
}
} // end of for loop
p1[n1] = NULL; //setting the place in the array to NULL
p2[n2] = NULL; //setting the place in the array to NULL
p3[n3] = NULL; //setting the place in the array to NULL
int dir1[2], dir2[2]; // integers for directing
pipe(dir1); //pipe
pipe(dir2); //pipe
pd = fork(); // first fork for command 1
if(pd == 0)
{
dup2(dir1[1] , 1); // duplicate write end of p1->p2 pipe stdout
close(dir1[0]);
close(dir1[1]);
close(dir2[0]);
close(dir2[1]);
execvp(p1[0], p1); //execute command p1
}
else if(pd>0) //the parent
{
pd2 = fork(); // fork second chil to execute grep
if(pd2 == 0)
{
dup2(dir1[0], 0); // duplicate read end of p1->p2 to stdin of p2
if(a == 2) // if second pipe was found
{
dup2(dir2[1], 1);
}
//close bothe ends of all created dir pipes
close(dir1[0]);
close(dir1[1]);
close(dir2[0]);
close(dir2[1]);
execvp(p2[0], p2); //execute command p2
}
else if(pd2 > 0)
{
if(a == 2)
{
pd3 = fork();
if(pd3 == 0)
{
dup2(dir2[0], 0);
//close bothe ends of all created dir pipes
close(dir1[0]);
close(dir1[1]); ...
3. char* p1[10] // variable for command 1
char* p2[10] // variable for command 2
char* p3[10] // variable for command 3
int num = 0; // integer for amount of pipes
int n1 = 0; // interger for command 1 array
int n2 = 0; // integer for command 2 array
int n3 = 0; // integer for command 3 array
int status; // for status
pid_t pd, pd2, pd3; //variables for pid to be forked
for (int i=0; i<size; i++) //size of command line input
{
if(strcmp(pipes[i], "|") == 0) // if the pipe is found
{
num++; //increment the counter
}
else if(num == 0) // if no pipe found
{
4. p1[n1] = pipes[i]; //place the command and argument into
p1
n1++; // incrementing place in command 1 array
}
else if(num == 1) // if 1 pipe is found
{
p2[n2] = pipes[i]; //place the command and argumemnt
into p2
n2++; //increment place in command 2 array
}
else if (num == 2) // if 2 pipes are found
{
p3[n3] = pipes[i]; //place the command and argumemnt
into p3
n3++; //increment place in command 3 array
}
} // end of for loop
p1[n1] = NULL; //setting the place in the array to NULL
p2[n2] = NULL; //setting the place in the array to NULL
5. p3[n3] = NULL; //setting the place in the array to NULL
int dir1[2], dir2[2]; // integers for directing
pipe(dir1); //pipe
pipe(dir2); //pipe
pd = fork(); // first fork for command 1
if(pd == 0)
{
dup2(dir1[1] , 1); // duplicate write end of p1->p2 pipe
stdout
close(dir1[0]);
close(dir1[1]);
close(dir2[0]);
close(dir2[1]);
6. execvp(p1[0], p1); //execute command p1
}
else if(pd>0) //the parent
{
pd2 = fork(); // fork second chil to execute grep
if(pd2 == 0)
{
dup2(dir1[0], 0); // duplicate read end of p1->p2 to stdin
of p2
if(a == 2) // if second pipe was found
{
dup2(dir2[1], 1);
}
//close bothe ends of all created dir pipes
close(dir1[0]);
close(dir1[1]);
close(dir2[0]);
7. close(dir2[1]);
execvp(p2[0], p2); //execute command p2
}
else if(pd2 > 0)
{
if(a == 2)
{
pd3 = fork();
if(pd3 == 0)
{
dup2(dir2[0], 0);
//close bothe ends of all created dir pipes
close(dir1[0]);
close(dir1[1]);
close(dir2[0]);
9. } // end of else if(pd>0)
else
{
perror("FORK FAILURE");
}
// only the parent gets here and close all the pipes and wait for
the 3 children to finish
close(dir1[0]);
close(dir1[1]);
close(dir2[0]);
close(dir2[1]);
for (int i = 0; i<(a+1); i++)
{
wait(&status); // waiting for the status
}
67. 86
Solved Problem 3
Nelson’s Hardware Store stocks a 19.2 volt cordless drill that is
a popular seller. Annual demand is 5,000 units, the ordering
cost is $15, and the inventory holding cost is $4/unit/year.
a.What is the economic order quantity?
b.What is the total annual cost for this inventory item?
a. The order quantity is
EOQ = =
2DS
H
2(5,000)($15)
$4
= 37,500 = 193.65 or 194 drills
b.The total annual cost is
C = (H) + (S) =
Q
2
D
Q
($4) + ($15) = $774.60
194
2
5,000
194
92. SmallCarry Bag LargeSauce Panni for Veg PackingBrown
BagCarry Bag SmallRubber Band
Nice Touch Hygiene
Nice Touch Hygiene is a company which produces tissues and
supplies hygienic products like sanitizers, hand wash, waste
baskets, cleaning equipment and chemicals. They are the
distributers of TTS Italy and an exclusive distributer of Jofel
Dispensers. Nice Touch produces a large variety of tissues; such
as face tissues, wet tissues, toilet papers, hand towels etc. The
main objective of the company is to produce quality products
and create a value in the minds of their customers. Nice Touch
serves both the B2B and B2C customers.
B2B customers: Facility management, cleaning companies,
retailers as well as other selective tissue company brands by
producing tissues to be sold under their respective brands.
B2C customers: Five-star, three star and four-star hotels,
restaurants.
The above customers which the company serves now are called
away from home market, which means these are the products
which customers cannot get from a grocery store or
hypermarkets for personal use. The products are supplied with a
contract of two years with their customers
Future Goals (entering home market)
Nice Touch has plans of entering the home market, making their
products available to customers, by supplying it to the grocery
stores and hypermarkets. By entering this market, they will be
exposed to various threats due to high competition. The target
segments for this market are both the premium customers and
the economy customers. The company will approach the
premium customers with specially designed and well-presented
tissue boxes and the economy customers will be presented with
simple tissue boxes with smaller size tissues without
compromising on the quality, making it available for the
customers at a lower price.
Cost structure
93. · Salaries of 60 staff
· Machine depreciation and maintenance
· Rent (one showroom and two stores)
Promotional activities
Offering gifts and vouchers annually to the employees of the
businesses where Nice Touch Products are bought and used, to
enhance customer relations.
Marketing
· Advertisements
· Personal selling
Competition
· Gulf Paper Industry
· Jasoor Factory
· National Paper Industry.
Flash Rent a car WLL.
Flash rent a car provides rentals of a large variety of vehicles;
Sedans, SUV’s, Pick up’s, vans and Buses. These rentals are
provided to the customers with or without drivers based on their
requirements. The company provides quality services by
providing their customers with on time car maintenance and
replacement of cars in case of accidents or car breakdowns. The
firm provides vehicles of Toyota, KIA, Honda and Nissan.
94. The firm focuses on B2C, there are different types of services
they offer, which are:
· Spot rentals for Individuals: Spot rental means renting out to
individuals on day to day basis. The car will be rented out by
securing an advance and the passport of the individuals.
· Monthly/Weekly: Renting vehicle to customers on weekly or
monthly basis according to customer demand.
· Car leasing to companies: Providing vehicles on annual bases
or with a contract of two years.
Customer Complaints
Customer care is a very important factor in this industry since
the firms with better customer service has the competitive
advantage. The complaints received by the customers are
normally regarding vehicle breakdown or vehicle problems and
the complaints should be dealt with no time delay by
replacement or fixing the complaints. The operations
department of Flash Rent a Car is always available to the
customer’s, resolving customer complaints.
Offers
· Commission on reference
· Discount on long term contracts
Variables/ factors considered in pricing
· Market study
· Vehicle price
· Cost of maintenance
· Resale value
Marketing
· Advertisements- Qatar Living, Facebook, Newspapers and
WhatsApp, Emails.
· Website- Is an identity of the firm, it helps people to get their
contacts details, location and the services they offer.
· Direct Sales- visiting clients
CRM- customized software for vehicle tracking.
Other Income
As per the law in Qatar, rent a car companies can only rent out
cars which are less than five years old. After five years these
95. cars will be sold which is another income for the company.
PROJECT GUIDELINES
The guidelines below will be updated whenever deemed
necessary. General
Project Subjects
· The ultimate purpose of the project is to show the ability of
the students to link the concepts studied in the chapter 9 with
the real‐world.
· The subject of the project must be clearly related to the
selected chapter. It does not have to cover the whole chapter,
but it is expected to relate to the most important concept(s) in
the chapter. The subject is also expected to be relevant to Qatar.
· Each group a case project (please note that the case project is
different from the case analysis). o
· o A case is a description and a resolution of a problem related
to some of the concepts in the chapter. The ideal is to have a
real problem (from a real situation); but it is acceptable to
invent an imaginary one as long as it is realistic. The problem
can also be based on a case from the literature (which must be
duly cited).
· The case is necessarily related to Qatar
Important Notes
All groups are expected to:
· Read these guidelines very carefully before starting the
project.
· Read the whole chapter (especially the examples and the
cases) in the book (not just rely on the slides) before starting
the project.
· Include in the presentation as well as in the report a title page
that provides: o Course name, course code and section number
o Chapter number and title o Title of the project o Name and ID
number of each student in the group (the names have to be in
96. the same order as the presentation; the first name is that of the
student that presents the first part, the second name is that of
the student that presents second, etc…)
o Date of the presentation
· Make the presentation file (whether video or slides) available
to the instructor and the students at least 12 hours before the
start of the class.
· Limit the presentation, in terms of time, to around 15 to 20
minutes.
· Have all the students of the group participate equally in the
presentation and in answering the questions.
· 750‐1,000 words for case projects.
· Submit the report using SafeAssign no later than one week
after the presentation (Only one student in each group should
submit the project on behalf of the entire group)
· Tell whether the same project has been or will be used for a
different course (Failing to provide this information will be
considered as plagiarism).
· Provide the references for the data in order to ensure
verifiability thereof. Grading Criteria
· The presentation is out of 7 points while that of the report is
out of 5.
· The grading scheme for the group presentation is as follows:
Criterion
Weightage
How successful were the students in describing the application
of some of the chapter concepts in a real‐world organization?
100
How good was the delivery? How clear, how organized, and
how coherent was it?
10
How informative was the video? How clear was it? How
understandable was it? How interesting and how original was it?
30
To what extent is the video related to the chapter? How
successful were the students in proving their ability to
97. effectively explain the concepts studied in the chapter?
30
· The grading scheme for the report is as follows:
Criterion
Weightage
How successful were the students in describing the application
of some of the chapter concepts in a real‐world organization?
100
How well‐written, clear, organized, and coherent is the report?
15
To what extent does the report explain the video?
15
To what extent does the report show the relation of the video to
the chapter?
20 Case Projects
Deliverables
This type of project has two deliverables: a presentation and a
report.
· Both the presentation and the report must include two major
parts (clearly separated): o The problem: This part is a
description of the problem faced by the organization from the
perspective of non‐technical persons.
o The solution: This part is the solution proposed by the group
to the problem. It is like a technical report to be presented to
the company.
· In the presentation part, the students introduce their project,
present their slides (see Appendix B), and answer the questions
of the other students and the instructor.
· The report is a Word document whose content must introduce
the organization, describe the project, explain how the data
were obtained, and provide the references. However, the most
two important parts are the presentation of the problem and the
solution proposed.
Grading Criteria
98. · The presentation is out of 5 points while that of the report is
out of 7.
· The grading scheme for the group presentation is as follows:
Criterion
Weightage
How successful were the students in proving their ability to
effectively apply the concepts studied in the chapter to a
real‐world situation?
100
How good was the delivery? How clear, organized, and coherent
was the presentation?
10
How pertinent are the data? How reliable are they? How
realistic is the problem? To what extent is it related to Qatar?
How interesting and how original is the problem? To what
extent is it related to the chapter?
20
How suitable is the solution? How convincing is it? To what
extent was the course helpful in finding the solution?
20
· The grading scheme for the report is as follows:
Criterion
Weightage
How successful were the students in proving their ability to
effectively apply the concepts studied in the chapter to a real‐
world situation?
100
How well‐written, clear, organized, and coherent is the report?
25
How pertinent are the data? How reliable are they? How
realistic is the problem? To what extent is it related to Qatar?
How interesting and how original is the problem? To what
extent is it related to the chapter?
20
How suitable is the solution? How convincing is it? To what
extent was the course
99. 25
helpful in finding the solution?
Appendix A: Group Work Contribution Policy
· To ensure more equity in the grading of group works (projects,
cases, etc…), each group with variation in the contribution of
its members is required to complete the contribution form.
· This form is not required if all the members of the group agree
that they contributed equally to the work.
· The grade of each member within the group depends on his/her
contribution.
· The sum of all the contributions must equal 100%.
· Although it is better to reach a consensus, this may not be
possible all the time. In such a case, the group can submit more
than one form with one being completed by two or three
students, for example, while the other one being completed by
the other member(s) of the group. However, no student is
allowed to approve more than one form.
· The form has to be sent by email by one of the students of the
group the same day of the submission of the work on Bb. The
student who sends the form is required to copy (cc) all the
students who approved it.
· If the members of the group agree on getting the same grade
they don’t have to complete any contribution form.
· The contribution form is as provided below:
Project Contribution Form
Student Number
Student Name
Contribution in %
100. Total
100% Appendix B: Dynamic Delivery
For a dynamic delivery, the students presenting their project
should try to:
· Avoid overloaded slides; try to have 10 to 15 slides, 5 to 10
bullets per slide, and 5 to 10 words per bullet.
· Stand up tall and straight, stand on both feet, and move
naturally, but not too much.
· Gesture when appropriate.
· Speak naturally and conversationally.
· Use an outline for the presentation.
· Have their notes ready, but not to depend on them.
· Use short sentences for emphasis, longer sentences for
explanation and discussion.
· Be dynamic in their delivery.
· Talk to the audience communicatively (establishing eye
contact).
Profit Crisis in the Restaurant Business
A leading Pakistani Cuisine Restaurant in Qatar, Qutba, faced
issues with cash flow and profitability. Further investigation
with the restaurant owner revealed poor inventory management
and wastage. While trying to salvage the situation, the
restaurant owner tried various methods to tackling inventory
management issues but always ended up affecting the quality of
the food. Reverting back the quality, reduced the profits and
created cash flow problems. The specific issues faced by the
restaurant owner are discussed below
Issues related to Inventory control and wastage faced by the
restaurant are as follows:
1. Issues with availability of fresh produce, meats and poultry:
The vegetable markets and wholesaler of meats and poultry are
at a far distance from the restaurant location and operate within
101. certain hours. The delivery schedule from the wholesalers are
limited and are not able to provide on demand.
2. Issues with wastage at end of service: The restaurant faced
issues with having to throw both cooked and fresh ingredients at
end of service every night. Being a full service restaurant, a
long menu leads to having to prepare for every item on the
menu. The demand however cannot be accurately predicted.
While there is an element of process while preparing the final
product, it is continuous and short. The inventory cannot be
divided into raw material, work in progress and finished good.
This is especially the case due to the fact that this is not a
“McDonald” style, quick service restaurant. Every dish is
prepared fresh on order. Analyzing the restaurant industry in
Qatar, especially in context of material availability and
logistics, the type of inventory category it falls under is
operational inventory.
Since the inventories lead time is one day for almost all
ingredients, cycle and pipeline categories do not fit in the
restaurant industry. However, Safety and Anticipatory
inventories need to be stocked for emergency or unexpected
demand. Since this is a “make to order” restaurant and there is
no significant ordering costs, Economic Order Quantity does not
particularly apply in this scenario.
With the above constraints in mind, an ABC analysis was
recommended to accurately stock and create the possibility for
repeatability of ingredients. The list of inventory items and the
costs was analyzed to find items for closets attention and
tightest control. With this information, four areas of
improvements was recommended to the restaurant owner as
follows:
1. Sales Forecast: It was recommended to analyze daily sales
from previous years in an attempt to create a weekly forecast.
Similarly, Analyze months with greater sales and special
occasions like New Years, Ramadhan and Eid holidays. The
sales forecast will help identify the quantity of ingredients to be
ordered. To do this, recipe management is necessary.
102. 2. Recipe Management: An as accurate as possible, every
ingredient for every item on the menu needs to be calculated.
The idea is to as accurately as possible maintain inventory, in
an effort to avoid wastage but at the same time maintain the
quality levels.
3. Mass Order discounts: Negotiate mass order discounts with
vendors and wholesalers to reduce unit cost on ingredients
while keeping in mind storage cost, wastage and freshness of
the produce.
4. Re-Order levels: In an effort to reduce the complexity of
calculating when to re-order, create bins of the size of
appropriate stock that needs to be maintained. Create visual
markers to accommodate lead times for all ingredients.
The above recommendations will provide fruit only when they
are constantly reviewed for effectiveness and efficiency. Every
business has its own set of quality standards, customer
satisfaction standards and expectation of profits. The restaurant
industry is particularly challenging due to the fact that entry
barriers are minimum and what is in fashion today may not be
the choice of customers tomorrow. The additional challenge is
Pakistani/Indian cuisine is that they have an extensive menu.
The extensive menu is extremely ingrained into the psychology
of the customers. This results into a downward spiral for
restaurants, where they are trying desperately to create profits,
while the inventories eat up the profits.
103. My suggestion about the case formation
First part of the case
1. We can start the case with the problems that are directed by
the restaurants in general and their need to fresh food and
because food generally has a specific expiration date ... I wrote
already two up but we can add more e important questions for
the case : 1 - the quantity we need to provide 2 - when we need
to provide
2. Also one of the problems: pressure of small inventions and
The points on page 340 We can apply which suitable for the
restaurants
3. Also we can talk about the type of inventory. In the
restaurants
*The second part*:
Solution
s / Be the answer to quantity and time ..
I think it is possible to analyze the Excel sheet and see the more
requested dishes in the restaurant and its components .. and
choose it as an example of the solution to the restaurant.
104. We can choose a technique or more of the operational
inventories ...Or EOQ if they are used for the restaurant!
Or continue review system In this case, I think the second type
for the demands to be Variable or the third for the Demands and
the time are Variable Or we can use the Q system
I think this is the most appropriate way to calculate them and to
know the quantitative result and the time we need each request
...
*Note*:
The Excel is the one in which it is written, in which the
invoices are as an example of the dimension, and in it the
ingredients for some dishes ... so be the source of analysis of
the data for us because we give it to Dr ..
#include <string.h>
void StoreInputToChar2DArray(char str[], char args[][100],
char seperator)
{
105. int startIndexCopy = 0; // Starting index of str to start
copying string into args[]
int indexToCopyTo = 0; // Which index of args[] to copy to
int lastIndex = 0; // Know when to start copying string for
each space sepearted strings
int charFound = 0;
int lastWasSpace = 0;
// Begin processing user input
for(int i = 0; i < strlen(str)+1; i++)
{
// Copy everytime a char is found
if(str[i] == seperator)
{
106. if(indexToCopyTo == 0)
{
strncpy(args[indexToCopyTo], str+startIndexCopy, i-
lastIndex);
strcat(args[indexToCopyTo], "0");
// Remove spaces before and after string
int lastCharIndex;
for(int j = strlen(args[indexToCopyTo])-1; j >= 0; j--
)
{
if(args[indexToCopyTo][j] == ' ')
121. lastIndex = i;
}
}
// Put "0" as the last element to know when to stop searching
array
strcpy(args[indexToCopyTo],"0");
return;
}
void StoreInputToChar2DArray2(char str[], char args[][100],
char seperator)
{
122. int startIndexCopy = 0; // Starting index of str to start
copying string into args[]
int indexToCopyTo = 0; // Which index of args[] to copy to
int lastIndex = 0; // Know when to start copying string for
each space sepearted strings
int spaceFound = 0;
// Begin processing user input
for(int i = 0; i < strlen(str)+1; i++)
{
// Copy everytime a char is found
if(str[i] == seperator && str[i+1] != ' ')
{
129. #include <sys/types.h>
#include <sys/file.h>
void StoreInputToChar2DArray(char str[], char args[][100],
char seperator); // Seperate the commands seperated by a
semicolon
void StoreInputToChar2DArray2(char str[], char args[][100],
char seperator); // Converts each command into a 2d array
void ClearCharArrays(char args[][100], char* args2[], char
str[], int strSize); // Clear character arrays for next user input
#endif
#include "header.h"
130. int main()
{
while(1)
{
char args[100][100]; // Semicolon seperated input goes
here
char str[512]; // Read in input into here
pid_t pid; // For executing commands with a child
process
int usedChild = 0; // Flag for checking if child process
was used for command
int numArrEle = 0; // For keeping track of how many
space sepearted strings there are in a command
131. // Ask and take in user input
printf("prompt> ");
fgets(str, 513, stdin);
// Removes the newline character from fgets
int ln = strlen(str)-1;
if (str[ln] == 'n')
{
str[ln] = '0';
}
StoreInputToChar2DArray(str, args, ';'); // Seperate
semicolon seperated input
132. // Run loop based on number of commands and execute
each one
for(int i = 0; i < 100; i++)
{
// Don't run command if it's whitespace
if(strcmp(args[i], "0") == 0)
{
continue;
}
char args2[100][100]; // Passed into the exec()
functions, after converting to char pointer array
char* args3[100]; // This is what is passed into the
133. exec() functions
StoreInputToChar2DArray2(args[i], args2, ' '); //
Seperate space seperated input
// Store 2d array into the char pointer array
for (int j = 0; j < 100; j++)
{
if (strcmp(args2[j], "0") == 0) // Let's us know when
to stop searching array
{
numArrEle = j;
args3[j] = NULL;
break;
134. }
args3[j] = args2[j];
}
// Run built in "cd" command
if(strcmp(args3[0], "cd") == 0)
{
if(args3[1] == NULL)
{
char argument[50] = "/home/";
char* name = getenv("USER");
strcat(argument, name);
137. if(fd == -1 || stdOut == -1)
{
perror("open error");
exit(EXIT_FAILURE);
}
dup2(fd, 1);
close(fd);
args3[numArrEle-2] = NULL;
// Now run command and output to file
pid = fork();
usedChild = 1;
138. if (pid > 0)
{
// Wait for child process to finish before
prompting user for input again
wait((int*)0);
}
else if (pid == 0)
{
// Command is executed using execvp()
if (execvp(args3[0], args3) == -1)
{
printf("%s: command not foundn",
139. args2[0]);
break; // Break child process so it won't
loop
}
}
else
{
perror("fork errorn");
}
// Restore stdout
dup2(stdOut, 1);
close(stdOut);
142. prompting user for input again
wait((int*)0);
}
else if (pid == 0)
{
// Command is executed using execvp()
if (execvp(args3[0], args3) == -1)
{
printf("%s: command not foundn",
args2[0]);
break; // Break child process so it won't
loop
}
}
144. {
pid = fork();
usedChild = 1;
if (pid > 0)
{
// Wait for child process to finish before
prompting user for input again
wait((int*)0);
}
else if (pid == 0)
{
// Command is executed using execvp()
145. if (execvp(args3[0], args3) == -1)
{
printf("%s: command not foundn", args2[0]);
break; // Break child process so it won't loop
}
}
else
{
perror("fork errorn");
}
}
// Clear arrays
int strSize = strlen(args[i]);
147. return 0;
}
BACKGROUND
A shell provides a command-line interface for users. It
interprets user commands and
executes them. Some shells provide simple scripting terms, such
as if or while, and
allow users to make a program that facilitates their computing
environment. Under the
hood, a shell is just another user program. The file /bin/bash is
an executable file for
the bash shell. The only thing special about your login shell is
that it is listed in your
login record so that /bin/login (i.e., the program that prompts
you for your
password)
knows what program to start when you log in. If you run "cat
/etc/passwd", you will
148. see the login records of the machine.
PROGRAM DESCRIPTION
GROUP COLLABORATIVE PORTION
In this assignment, you will implement the shell “engine” as the
“group” component,
where all members are responsible for the following
functionality:
A Command-Line Interpreter, or Shell
Your shell should read the line from standard input (i.e.,
interactive mode) or a
file (i.e., batch mode), parse the line with command and
arguments, execute the
command with arguments, and then prompt for more input (i.e.,
the shell prompt)
when it has finished.
1. Interactive Mode
In interactive mode, you will display a prompt (any string of
your choosing)
and the user of the shell will type in a command at the prompt.
2. Batch Mode
In batch mode, your shell is started by specifying a batch file on
its command
line. The batch file contains the list of commands that should be
executed. In
149. batch mode, you should not display a prompt, but you should
echo each line
you read from the batch file back to the user before executing it.
You will need to use the fork() and exec() family of system
calls. You may
2 of 8
not use the system() system call as it simply invokes the
system’s /bin/bash
shell to do all of the work.
You may assume that arguments are separated by whitespace.
You do not have
to deal with special characters such as ', ", , etc. However, you
will need to
handle the redirection operators (< and >) and the pipeline
operator (|), which
will be specified in the “individual” portion of this assignment.
Each line (either in the batch file or typed at the prompt) may
contain multiple
commands separate with the semicolon (;) character. Each
command separated
150. by a ; should be run sequentially, but the shell should not print
the next prompt
or take more input until all of these commands have finished
executing (the
wait() or waitpid() system calls may be useful here).
You may assume that the command-line a user types is not
longer than 512
bytes (including the 'n'), but you should not assume that there
is any restriction
on the number of arguments to a given command.
INDIVIDUAL PORTION
In this assignment, each member of the group will implement
the following components
as defined below. This means that the individual group member
responsible for each
portion MUST commit in GitLab the code that supports their
responsible area.
Built-In Commands
151. Every shell needs to support a number of built-in commands,
which are functions
in the shell itself, not external programs. Shells directly make
system calls to
execute built-in commands, instead of forking a child process to
handle them.
Each group member is expected to implement 1 of the following
built-in
commands.
Note that the expectation for this assignment assumes that a
group contains 4
students, but if, for some reason, a team has only 3 students,
then only 3 of the
following built-in commands would need to be supported (i.e., 1
for each group
member).
1. Add a new built-in cd command that accepts one optional
argument, a
directory path, and changes the current working directory to
that directory. If
no argument is passed, the command will change the current
working
directory to the user’s HOME directory. You may need to
invoke the chdir()
152. system call.
2. Add a new built-in exit command that exits from the shell
itself with the
exit() system call. It is not to be executed like other programs
the user
types in. If the exit command is on the same line with other
commands, you
should ensure that the other commands execute (and finish)
before you exit
your shell.
These are all valid examples for quitting the shell:
prompt> exit
3 of 8
prompt> exit; cat file1
prompt> cat file1; exit
3. Add a new built-in path command that allows users to show
the current
153. pathname list, append one pathname, or remove one pathname.
In your shell
implementation, you may keep a data structure to deal with the
pathname list.
If you do not use execle() or execve() that allows you to execute
with
your own environment variables, you will need to add it to the
“real” PATH
environment variable for executables in the path to work
correctly. The initial
value of path within your shell shall be the pathname list
contained in the
PATH environment variable. Implement the path command as
follows:
set. It should
show pathnames separated by colons. For example,
"/bin:/user/bin".
may
154. assume that only one pathname is added at a time.
- ./bin removes the pathname to the path variable. You
may
assume that only one pathname is removed at a time.
You may assume that there are no duplicate pathnames present,
being
added, or being deleted. You will restore your PATH
environment variable to
its original state (i.e., before your shell was invoked) when the
user exits your
shell.
4. Add a new built-in myhistory command that lists the shell
history of
previous commands run in your shell (not the bash shell). Note
that this does
not have to work with the up-arrow key as in bash, but only
with a new
myhistory command run inside your shell. You may not make
use of the
155. history built-in command, but instead keep track of your history
of
commands in some sort of data structure. Your myhistory built-
in command
should support a history of 20 most recent commands (i.e., this
means that
the 21st command will overwrite the 1st command, for
example). Your
myhistory command should support a couple flags: -c to clear
your
myhistory list by deleting all entries, and -e
<myhistory_number> to
execute one of your twenty myhistory commands in your list.
Redirection, Pipelining, Signal Control, and Alias Support:
1. Extend your shell with I/O redirection (mandatory for teams
of 3 or 4)
When you start a command, there are always three default file
streams open:
stdin (maps input from the keyboard by default), stdout (maps