SlideShare a Scribd company logo
Overview
In this assignment you will write your own shell in C. The shell
will run command line
instructions and return the results similar to other shells you
have used, but without many
of their fancier features.
In this assignment you will write your own shell, called
smallsh. This will work like the
bash shell you are used to using, prompting for a command line
and running commands,
but it will not have many of the special features of the bash
shell.
Your shell will allow for the redirection of standard input and
standard output and it will
support both foreground and background processes.
Your shell will support three built in commands: exit, cd, and
status. It will also support
comments, which are lines beginning with the # character.
Specifications
All execution, compiling, and testing of this program should be
done from the bash
prompt on the eos-class.engr.oregonstate.edu server.
Use the colon : symbol as a prompt for each command line. Be
sure you flush out the
prompt each time you print it, this makes the test script look
nicer.
The general syntax of a command line is:
command [arg1 arg2 ...] [< input_file] [> output_file] [&]
…where items in square brackets are optional. You can assume
that a command is made
up of words separated by spaces. The special symbols <, >, and
& are recognized, but
they must be surrounded by spaces like other words. If the
command is to be executed in
the background, the last word must be &. If standard input or
output is to be redirected,
the > or < words followed by a filename word must appear after
all the arguments. Input
redirection can appear before or after output redirection.
Your shell does not need to support any quoting; so arguments
with spaces inside them
are not possible.
Your shell should support command lines with a maximum
length of 2048 characters, and
a maximum of 512 arguments. You do not need to do any error
checking on the syntax of
the command line.
Command Execution
You will use fork, exec, and waitpid to execute commands. The
shell will wait for
completion of foreground commands (commands without the &)
before prompting for the
next command. The shell will not wait for background
commands to complete.
Background commands should have their standard input
redirected from /dev/null if the
user did not specify some other file to take standard input from.
What happens to
background commands that read from standard input if you
forget this?
Your shell should use the PATH variable to look for commands,
and it should allow shell
scripts to be executed (see below for the testing script, for
example). The right version
of the exec function will do this for you automatically. If a
command fails because the
shell could not find the command to run, then the shell will
print an error message and set
the exit status to 1.
After the fork but before the exec you must do any input/output
redirection. A redirected
input file should be opened for reading only; if your shell
cannot open the file for reading
it should print an error message and set the exit status to 1. A
redirected output file
should be opened for write only, it should be truncated if it
already exists or created if it
does not exist. If your shell cannot open the output file it should
print an error message
and set the exit status to 1.
The built-in command status can be used to print the exit status
of the last foreground
command. If a command (either a foreground or background
command) is terminated by
a signal, a message indicating which signal terminated the
process will be printed. The
shell will print the process id of a background process when it
begins. When a
background process terminates, a message showing the process
id and exit status will be
printed. You should check to see if any background processes
completed just before you
prompt for a new command and print the message then. In this
way the messages about
completed background processes will not appear during other
running commands, though
the user will have to wait until they complete some other
command to see these messages
(this is the way the C shell and Bourne shells work). You will
need to use waitpid to
check for completed background processes.
Be sure that a CTRL-C interrupt from the keyboard does not
terminate your shell, but
only the foreground command it is running.
Background processes should not be terminated by a CTRL-C
signal, nor should they
send their standard output to the screen (consider /dev/null,
instead, as needed).
Built-in Commands
Your shell will support three built in commands: exit, cd, and
status.
The exit command exits the shell. It takes no arguments. When
run, it must kill any
other processes or jobs that your shell has started before it
terminates your shell itself.
The cd command changes directories. By itself, it changes to
the directory specified in
the HOME environment variable. It can also take one argument,
the path of the directory
to change to. Note that this is a working directory: when
smallsh exits, the pwd will be
the original pwd when smallsh was launched. Your cd command
should support both
absolute and relative paths.
The status command prints out the exit status or terminating
signal of the last foreground
process. You do not have to support input/output redirection for
these built in commands
and they do not have to set any exit status.
These three built-in commands are the only ones that your shell
will handle itself - all
others are simply passed on to a member of the exec() family of
functions (which
member is up to you).
Finally, your shell should allow blank lines and comments. Any
line that begins with the
# character is a comment line and should be ignored. A blank
line (one without any
commands) should do nothing; your shell should just reprompt
for another command.
Example
Here is an example:
$ smallsh
: ls
junk smallsh smallsh.c
: ls > junk
: status
exit value 0
: cat junk
junk
smallsh
smallsh.c
: wc < junk
3 3 23
: test -f badfile
: status
exit value 1
: wc < badfile
smallsh: cannot open badfile for input
: status
exit value 1
: badfile
badfile: no such file or directory
: sleep 5
^Cterminated by signal 2
: status
terminated by signal 2
: sleep 15 &
background pid is 4923
: ps
PID TTY TIME CMD
4923 pts/4 0:00 sleep
4564 pts/4 0:03 tcsh-6.0
4867 pts/4 1:32 smallsh
:
:
: # that was a blank command line, this is a comment line
background pid 4923 is done: exit value 0
: # the background sleep finally finished
: sleep 30 &
background pid is 4941
: kill -15 4941
background pid 4941 is done: terminated by signal 15
: pwd
/nfs/stak/faculty/b/brewsteb/CS344/prog3
: cd
: pwd
/nfs/stak/faculty/b/brewsteb
: cd CS344
: pwd
/nfs/stak/faculty/b/brewsteb/CS344
: exit
$
In addition to your shell needing to replicate the above example
in functionality, this
assignment is provided with the actual grading test script that
will be used to assign
your program a grade. To run it, place it in the same directory
as your compiled shell, and
run this command from a bash prompt:
$ p3testscript 2>&1
or
$ p3testscript 2>&1 | more
or
$ p3testscript > mytestresults 2>&1
Don’t worry if the spacing, indentation, or look of the output of
the script is different than
when you run it interactively: that won’t affect your grade. The
script may add extra
colons at the beginning of lines or do other weird things. Use it
to prepare for your grade,
but base the look and feel of your program on the interactive
running of your shell
What to submit
Please submit a single zip file of your program code, which may
be in as many different
files as you want. Also, inside that zip file, provide a file called
readme.txt that contains
instructions on HOW to compile your code; you may compile
your code however you
wish. DO NOT include a copy of the testing script.
The graders will compile your code according to your exact
specifications. They will
make a reasonable effort to make it work, but if it doesn’t
compile, you’ll receive a zero
on this assignment.
Hints
I HIGHY recommend that you develop this program directly on
the eos-class server.
Doing so will prevent you from having problems transferring
the program back and forth,
and having compatibility problems.
If you do see ^M characters all over your files, try this
command:
$ dos2unix bustedFile
Grading
Once the program is compiled, according to your specifications,
your shell will be
executed to run a few sample commands against (ls, status, exit,
in that order). If the
program does not successfully work on those commands, it will
receive a zero. If it works,
it will have the p3testscript program ran against it (as detailed
above) for final grading.
Points will be assigned according to the test script.
150 points are available in the test script, while the final 10
points will be based on your
style, readability, and commenting. Comment well, often, and
verbosely: we want to see
that you are telling us WHY you are doing things, in addition to
telling us WHAT you are
doing.
OverviewSpecificationsHintsGrading

More Related Content

Similar to OverviewIn this assignment you will write your own shell i.docx

Hello. I was wondering if I could get some help on this C programmin.pdf
Hello. I was wondering if I could get some help on this C programmin.pdfHello. I was wondering if I could get some help on this C programmin.pdf
Hello. I was wondering if I could get some help on this C programmin.pdf
fashionfootwear1
 
Mastering unix
Mastering unixMastering unix
Mastering unix
Raghu nath
 
OS_lab_file.pdf
OS_lab_file.pdfOS_lab_file.pdf
OS_lab_file.pdf
KarthickS942388
 
Chapter 2: Introduction to Bash Scripting
Chapter 2: Introduction to Bash ScriptingChapter 2: Introduction to Bash Scripting
Chapter 2: Introduction to Bash Scripting
azzamhadeel89
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1
tutorialsruby
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1
tutorialsruby
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
guestd9065
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
Jaibeer Malik
 
Bioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introductionBioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introduction
Prof. Wim Van Criekinge
 
Using Unix
Using UnixUsing Unix
Using Unix
Dr.Ravi
 
OSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with GoOSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with Go
Chris McEniry
 
intro unix/linux 08
intro unix/linux 08intro unix/linux 08
intro unix/linux 08
duquoi
 
Buffer overflow tutorial
Buffer overflow tutorialBuffer overflow tutorial
Buffer overflow tutorial
hughpearse
 
Bioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekingeBioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekinge
Prof. Wim Van Criekinge
 
dotor.pdf
dotor.pdfdotor.pdf
dotor.pdf
JaveedAhamed7
 
Chapter 1: Introduction to Command Line
Chapter 1: Introduction to  Command LineChapter 1: Introduction to  Command Line
Chapter 1: Introduction to Command Line
azzamhadeel89
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
brian_dailey
 
Chapter 1: Introduction to Command Line
Chapter 1: Introduction  to Command LineChapter 1: Introduction  to Command Line
Chapter 1: Introduction to Command Line
azzamhadeel89
 
2004 ugm-tips-tricks
2004 ugm-tips-tricks2004 ugm-tips-tricks
2004 ugm-tips-tricks
Shamoon Jamshed
 
Please write the mysh program in C and follow the guidelines specifi.pdf
Please write the mysh program in C and follow the guidelines specifi.pdfPlease write the mysh program in C and follow the guidelines specifi.pdf
Please write the mysh program in C and follow the guidelines specifi.pdf
amarndsons
 

Similar to OverviewIn this assignment you will write your own shell i.docx (20)

Hello. I was wondering if I could get some help on this C programmin.pdf
Hello. I was wondering if I could get some help on this C programmin.pdfHello. I was wondering if I could get some help on this C programmin.pdf
Hello. I was wondering if I could get some help on this C programmin.pdf
 
Mastering unix
Mastering unixMastering unix
Mastering unix
 
OS_lab_file.pdf
OS_lab_file.pdfOS_lab_file.pdf
OS_lab_file.pdf
 
Chapter 2: Introduction to Bash Scripting
Chapter 2: Introduction to Bash ScriptingChapter 2: Introduction to Bash Scripting
Chapter 2: Introduction to Bash Scripting
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
Bioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introductionBioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introduction
 
Using Unix
Using UnixUsing Unix
Using Unix
 
OSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with GoOSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with Go
 
intro unix/linux 08
intro unix/linux 08intro unix/linux 08
intro unix/linux 08
 
Buffer overflow tutorial
Buffer overflow tutorialBuffer overflow tutorial
Buffer overflow tutorial
 
Bioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekingeBioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekinge
 
dotor.pdf
dotor.pdfdotor.pdf
dotor.pdf
 
Chapter 1: Introduction to Command Line
Chapter 1: Introduction to  Command LineChapter 1: Introduction to  Command Line
Chapter 1: Introduction to Command Line
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
 
Chapter 1: Introduction to Command Line
Chapter 1: Introduction  to Command LineChapter 1: Introduction  to Command Line
Chapter 1: Introduction to Command Line
 
2004 ugm-tips-tricks
2004 ugm-tips-tricks2004 ugm-tips-tricks
2004 ugm-tips-tricks
 
Please write the mysh program in C and follow the guidelines specifi.pdf
Please write the mysh program in C and follow the guidelines specifi.pdfPlease write the mysh program in C and follow the guidelines specifi.pdf
Please write the mysh program in C and follow the guidelines specifi.pdf
 

More from alfred4lewis58146

For this assignment, students will need to observe the activities th.docx
For this assignment, students will need to observe the activities th.docxFor this assignment, students will need to observe the activities th.docx
For this assignment, students will need to observe the activities th.docx
alfred4lewis58146
 
For this assignment, select a human service organization from .docx
For this assignment, select a human service organization from .docxFor this assignment, select a human service organization from .docx
For this assignment, select a human service organization from .docx
alfred4lewis58146
 
For this Assignment, read the case study for Claudia and find tw.docx
For this Assignment, read the case study for Claudia and find tw.docxFor this Assignment, read the case study for Claudia and find tw.docx
For this Assignment, read the case study for Claudia and find tw.docx
alfred4lewis58146
 
For this assignment, download the A6 code pack. This zip fil.docx
For this assignment, download the A6 code pack. This zip fil.docxFor this assignment, download the A6 code pack. This zip fil.docx
For this assignment, download the A6 code pack. This zip fil.docx
alfred4lewis58146
 
For this assignment, create infographic using the Canva website..docx
For this assignment, create infographic using the Canva website..docxFor this assignment, create infographic using the Canva website..docx
For this assignment, create infographic using the Canva website..docx
alfred4lewis58146
 
For this assignment, compare  California during the Great Depression.docx
For this assignment, compare  California during the Great Depression.docxFor this assignment, compare  California during the Great Depression.docx
For this assignment, compare  California during the Great Depression.docx
alfred4lewis58146
 
For this assignment, create a 10- to 12-slide presentation in Mi.docx
For this assignment, create a 10- to 12-slide presentation in Mi.docxFor this assignment, create a 10- to 12-slide presentation in Mi.docx
For this assignment, create a 10- to 12-slide presentation in Mi.docx
alfred4lewis58146
 
For this assignment, begin by reading chapters 12-15 in Dr. Bells t.docx
For this assignment, begin by reading chapters 12-15 in Dr. Bells t.docxFor this assignment, begin by reading chapters 12-15 in Dr. Bells t.docx
For this assignment, begin by reading chapters 12-15 in Dr. Bells t.docx
alfred4lewis58146
 
For this assignment, assume you are the new Secretary of Homelan.docx
For this assignment, assume you are the new Secretary of Homelan.docxFor this assignment, assume you are the new Secretary of Homelan.docx
For this assignment, assume you are the new Secretary of Homelan.docx
alfred4lewis58146
 
For this assignment, address the following promptsIntroductor.docx
For this assignment, address the following promptsIntroductor.docxFor this assignment, address the following promptsIntroductor.docx
For this assignment, address the following promptsIntroductor.docx
alfred4lewis58146
 
For this assignment, analyze the play by focusing on one of the .docx
For this assignment, analyze the play by focusing on one of the .docxFor this assignment, analyze the play by focusing on one of the .docx
For this assignment, analyze the play by focusing on one of the .docx
alfred4lewis58146
 
For this assignment I would like you to answer these questions.docx
For this assignment I would like you to answer these questions.docxFor this assignment I would like you to answer these questions.docx
For this assignment I would like you to answer these questions.docx
alfred4lewis58146
 
For the Weekly Reports I need 2 reports. For the First two weeks the.docx
For the Weekly Reports I need 2 reports. For the First two weeks the.docxFor the Weekly Reports I need 2 reports. For the First two weeks the.docx
For the Weekly Reports I need 2 reports. For the First two weeks the.docx
alfred4lewis58146
 
For the shortanswer questions,you will need to respo.docx
For the shortanswer questions,you will need to respo.docxFor the shortanswer questions,you will need to respo.docx
For the shortanswer questions,you will need to respo.docx
alfred4lewis58146
 
For the sake of argument (this essay in particular), lets prete.docx
For the sake of argument (this essay in particular), lets prete.docxFor the sake of argument (this essay in particular), lets prete.docx
For the sake of argument (this essay in particular), lets prete.docx
alfred4lewis58146
 
For the proposal, each student must describe an interface they a.docx
For the proposal, each student must describe an interface they a.docxFor the proposal, each student must describe an interface they a.docx
For the proposal, each student must describe an interface they a.docx
alfred4lewis58146
 
For the project, you will be expected to apply the key concepts of p.docx
For the project, you will be expected to apply the key concepts of p.docxFor the project, you will be expected to apply the key concepts of p.docx
For the project, you will be expected to apply the key concepts of p.docx
alfred4lewis58146
 
For the past several weeks you have addressed several different area.docx
For the past several weeks you have addressed several different area.docxFor the past several weeks you have addressed several different area.docx
For the past several weeks you have addressed several different area.docx
alfred4lewis58146
 
For the Mash it Up assignment, we experimented with different ways t.docx
For the Mash it Up assignment, we experimented with different ways t.docxFor the Mash it Up assignment, we experimented with different ways t.docx
For the Mash it Up assignment, we experimented with different ways t.docx
alfred4lewis58146
 
For the first time in modern history, the world is experiencing a he.docx
For the first time in modern history, the world is experiencing a he.docxFor the first time in modern history, the world is experiencing a he.docx
For the first time in modern history, the world is experiencing a he.docx
alfred4lewis58146
 

More from alfred4lewis58146 (20)

For this assignment, students will need to observe the activities th.docx
For this assignment, students will need to observe the activities th.docxFor this assignment, students will need to observe the activities th.docx
For this assignment, students will need to observe the activities th.docx
 
For this assignment, select a human service organization from .docx
For this assignment, select a human service organization from .docxFor this assignment, select a human service organization from .docx
For this assignment, select a human service organization from .docx
 
For this Assignment, read the case study for Claudia and find tw.docx
For this Assignment, read the case study for Claudia and find tw.docxFor this Assignment, read the case study for Claudia and find tw.docx
For this Assignment, read the case study for Claudia and find tw.docx
 
For this assignment, download the A6 code pack. This zip fil.docx
For this assignment, download the A6 code pack. This zip fil.docxFor this assignment, download the A6 code pack. This zip fil.docx
For this assignment, download the A6 code pack. This zip fil.docx
 
For this assignment, create infographic using the Canva website..docx
For this assignment, create infographic using the Canva website..docxFor this assignment, create infographic using the Canva website..docx
For this assignment, create infographic using the Canva website..docx
 
For this assignment, compare  California during the Great Depression.docx
For this assignment, compare  California during the Great Depression.docxFor this assignment, compare  California during the Great Depression.docx
For this assignment, compare  California during the Great Depression.docx
 
For this assignment, create a 10- to 12-slide presentation in Mi.docx
For this assignment, create a 10- to 12-slide presentation in Mi.docxFor this assignment, create a 10- to 12-slide presentation in Mi.docx
For this assignment, create a 10- to 12-slide presentation in Mi.docx
 
For this assignment, begin by reading chapters 12-15 in Dr. Bells t.docx
For this assignment, begin by reading chapters 12-15 in Dr. Bells t.docxFor this assignment, begin by reading chapters 12-15 in Dr. Bells t.docx
For this assignment, begin by reading chapters 12-15 in Dr. Bells t.docx
 
For this assignment, assume you are the new Secretary of Homelan.docx
For this assignment, assume you are the new Secretary of Homelan.docxFor this assignment, assume you are the new Secretary of Homelan.docx
For this assignment, assume you are the new Secretary of Homelan.docx
 
For this assignment, address the following promptsIntroductor.docx
For this assignment, address the following promptsIntroductor.docxFor this assignment, address the following promptsIntroductor.docx
For this assignment, address the following promptsIntroductor.docx
 
For this assignment, analyze the play by focusing on one of the .docx
For this assignment, analyze the play by focusing on one of the .docxFor this assignment, analyze the play by focusing on one of the .docx
For this assignment, analyze the play by focusing on one of the .docx
 
For this assignment I would like you to answer these questions.docx
For this assignment I would like you to answer these questions.docxFor this assignment I would like you to answer these questions.docx
For this assignment I would like you to answer these questions.docx
 
For the Weekly Reports I need 2 reports. For the First two weeks the.docx
For the Weekly Reports I need 2 reports. For the First two weeks the.docxFor the Weekly Reports I need 2 reports. For the First two weeks the.docx
For the Weekly Reports I need 2 reports. For the First two weeks the.docx
 
For the shortanswer questions,you will need to respo.docx
For the shortanswer questions,you will need to respo.docxFor the shortanswer questions,you will need to respo.docx
For the shortanswer questions,you will need to respo.docx
 
For the sake of argument (this essay in particular), lets prete.docx
For the sake of argument (this essay in particular), lets prete.docxFor the sake of argument (this essay in particular), lets prete.docx
For the sake of argument (this essay in particular), lets prete.docx
 
For the proposal, each student must describe an interface they a.docx
For the proposal, each student must describe an interface they a.docxFor the proposal, each student must describe an interface they a.docx
For the proposal, each student must describe an interface they a.docx
 
For the project, you will be expected to apply the key concepts of p.docx
For the project, you will be expected to apply the key concepts of p.docxFor the project, you will be expected to apply the key concepts of p.docx
For the project, you will be expected to apply the key concepts of p.docx
 
For the past several weeks you have addressed several different area.docx
For the past several weeks you have addressed several different area.docxFor the past several weeks you have addressed several different area.docx
For the past several weeks you have addressed several different area.docx
 
For the Mash it Up assignment, we experimented with different ways t.docx
For the Mash it Up assignment, we experimented with different ways t.docxFor the Mash it Up assignment, we experimented with different ways t.docx
For the Mash it Up assignment, we experimented with different ways t.docx
 
For the first time in modern history, the world is experiencing a he.docx
For the first time in modern history, the world is experiencing a he.docxFor the first time in modern history, the world is experiencing a he.docx
For the first time in modern history, the world is experiencing a he.docx
 

Recently uploaded

Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
Chevonnese Chevers Whyte, MBA, B.Sc.
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Leena Ghag-Sakpal
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 

Recently uploaded (20)

Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 

OverviewIn this assignment you will write your own shell i.docx

  • 1. Overview In this assignment you will write your own shell in C. The shell will run command line instructions and return the results similar to other shells you have used, but without many of their fancier features. In this assignment you will write your own shell, called smallsh. This will work like the bash shell you are used to using, prompting for a command line and running commands, but it will not have many of the special features of the bash shell. Your shell will allow for the redirection of standard input and standard output and it will support both foreground and background processes. Your shell will support three built in commands: exit, cd, and status. It will also support comments, which are lines beginning with the # character. Specifications All execution, compiling, and testing of this program should be
  • 2. done from the bash prompt on the eos-class.engr.oregonstate.edu server. Use the colon : symbol as a prompt for each command line. Be sure you flush out the prompt each time you print it, this makes the test script look nicer. The general syntax of a command line is: command [arg1 arg2 ...] [< input_file] [> output_file] [&] …where items in square brackets are optional. You can assume that a command is made up of words separated by spaces. The special symbols <, >, and & are recognized, but they must be surrounded by spaces like other words. If the command is to be executed in the background, the last word must be &. If standard input or output is to be redirected, the > or < words followed by a filename word must appear after all the arguments. Input redirection can appear before or after output redirection. Your shell does not need to support any quoting; so arguments with spaces inside them
  • 3. are not possible. Your shell should support command lines with a maximum length of 2048 characters, and a maximum of 512 arguments. You do not need to do any error checking on the syntax of the command line. Command Execution You will use fork, exec, and waitpid to execute commands. The shell will wait for completion of foreground commands (commands without the &) before prompting for the next command. The shell will not wait for background commands to complete. Background commands should have their standard input redirected from /dev/null if the user did not specify some other file to take standard input from. What happens to background commands that read from standard input if you forget this? Your shell should use the PATH variable to look for commands, and it should allow shell scripts to be executed (see below for the testing script, for example). The right version
  • 4. of the exec function will do this for you automatically. If a command fails because the shell could not find the command to run, then the shell will print an error message and set the exit status to 1. After the fork but before the exec you must do any input/output redirection. A redirected input file should be opened for reading only; if your shell cannot open the file for reading it should print an error message and set the exit status to 1. A redirected output file should be opened for write only, it should be truncated if it already exists or created if it does not exist. If your shell cannot open the output file it should print an error message and set the exit status to 1. The built-in command status can be used to print the exit status of the last foreground command. If a command (either a foreground or background command) is terminated by a signal, a message indicating which signal terminated the process will be printed. The
  • 5. shell will print the process id of a background process when it begins. When a background process terminates, a message showing the process id and exit status will be printed. You should check to see if any background processes completed just before you prompt for a new command and print the message then. In this way the messages about completed background processes will not appear during other running commands, though the user will have to wait until they complete some other command to see these messages (this is the way the C shell and Bourne shells work). You will need to use waitpid to check for completed background processes. Be sure that a CTRL-C interrupt from the keyboard does not terminate your shell, but only the foreground command it is running. Background processes should not be terminated by a CTRL-C signal, nor should they send their standard output to the screen (consider /dev/null, instead, as needed). Built-in Commands
  • 6. Your shell will support three built in commands: exit, cd, and status. The exit command exits the shell. It takes no arguments. When run, it must kill any other processes or jobs that your shell has started before it terminates your shell itself. The cd command changes directories. By itself, it changes to the directory specified in the HOME environment variable. It can also take one argument, the path of the directory to change to. Note that this is a working directory: when smallsh exits, the pwd will be the original pwd when smallsh was launched. Your cd command should support both absolute and relative paths. The status command prints out the exit status or terminating signal of the last foreground process. You do not have to support input/output redirection for these built in commands and they do not have to set any exit status. These three built-in commands are the only ones that your shell will handle itself - all
  • 7. others are simply passed on to a member of the exec() family of functions (which member is up to you). Finally, your shell should allow blank lines and comments. Any line that begins with the # character is a comment line and should be ignored. A blank line (one without any commands) should do nothing; your shell should just reprompt for another command. Example Here is an example: $ smallsh : ls junk smallsh smallsh.c : ls > junk : status exit value 0 : cat junk junk
  • 8. smallsh smallsh.c : wc < junk 3 3 23 : test -f badfile : status exit value 1 : wc < badfile smallsh: cannot open badfile for input : status exit value 1 : badfile badfile: no such file or directory : sleep 5 ^Cterminated by signal 2 : status terminated by signal 2
  • 9. : sleep 15 & background pid is 4923 : ps PID TTY TIME CMD 4923 pts/4 0:00 sleep 4564 pts/4 0:03 tcsh-6.0 4867 pts/4 1:32 smallsh : : : # that was a blank command line, this is a comment line background pid 4923 is done: exit value 0 : # the background sleep finally finished : sleep 30 & background pid is 4941 : kill -15 4941 background pid 4941 is done: terminated by signal 15 : pwd /nfs/stak/faculty/b/brewsteb/CS344/prog3
  • 10. : cd : pwd /nfs/stak/faculty/b/brewsteb : cd CS344 : pwd /nfs/stak/faculty/b/brewsteb/CS344 : exit $ In addition to your shell needing to replicate the above example in functionality, this assignment is provided with the actual grading test script that will be used to assign your program a grade. To run it, place it in the same directory as your compiled shell, and run this command from a bash prompt: $ p3testscript 2>&1 or $ p3testscript 2>&1 | more or
  • 11. $ p3testscript > mytestresults 2>&1 Don’t worry if the spacing, indentation, or look of the output of the script is different than when you run it interactively: that won’t affect your grade. The script may add extra colons at the beginning of lines or do other weird things. Use it to prepare for your grade, but base the look and feel of your program on the interactive running of your shell What to submit Please submit a single zip file of your program code, which may be in as many different files as you want. Also, inside that zip file, provide a file called readme.txt that contains instructions on HOW to compile your code; you may compile your code however you wish. DO NOT include a copy of the testing script. The graders will compile your code according to your exact specifications. They will make a reasonable effort to make it work, but if it doesn’t compile, you’ll receive a zero
  • 12. on this assignment. Hints I HIGHY recommend that you develop this program directly on the eos-class server. Doing so will prevent you from having problems transferring the program back and forth, and having compatibility problems. If you do see ^M characters all over your files, try this command: $ dos2unix bustedFile Grading Once the program is compiled, according to your specifications, your shell will be executed to run a few sample commands against (ls, status, exit, in that order). If the program does not successfully work on those commands, it will receive a zero. If it works, it will have the p3testscript program ran against it (as detailed above) for final grading. Points will be assigned according to the test script. 150 points are available in the test script, while the final 10 points will be based on your
  • 13. style, readability, and commenting. Comment well, often, and verbosely: we want to see that you are telling us WHY you are doing things, in addition to telling us WHAT you are doing. OverviewSpecificationsHintsGrading