Programming Project #1 Fork and Command Shell PowerPoint Presentation, PPT - DocSlides

Programming Project #1 Fork and Command Shell PowerPoint Presentation, PPT - DocSlides

2019-03-01 4K 4 0 0

Description

CS-3013 . Operating Systems. Hugh C. Lauer. (Slides include materials from. Slides include materials from . Modern Operating Systems. , . 3. rd. ed. ., by Andrew . Tanenbaum. and from . Operating System Concepts. ID: 754398

Embed code:

Download this presentation



DownloadNote - The PPT/PDF document "Programming Project #1 Fork and Command ..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.

Presentations text content in Programming Project #1 Fork and Command Shell

Slide1

Programming Project #1Fork and Command Shell

CS-3013 Operating SystemsHugh C. Lauer (Slides include materials fromSlides include materials from Modern Operating Systems, 3rd ed., by Andrew Tanenbaum and from Operating System Concepts, 7th ed., by Silbershatz, Galvin, & Gagne)

CS-3013, C-Term 2012

Project #1, Fork and Command Shell

1

Slide2

Purpose

To practice using the fork and exec facilities of Unix/LinuxTo learn how to find and use on-line documentation about system calls and system facilities.man pagesTo become accustomed to speaking directly with the operating systemProject #1, Fork and Command Shell2CS-3013, C-Term 2012

Slide3

Programming Assignment

Build a command shell capable of running commands in the background:–Write a command called doit to execute another command and print out statisticsAdapt doit to become a basic shell that prompts for and executes commandsModify your shell to become shell2 to execute commands in the background

Project #1, Fork and Command Shell

3

CS-3013, C-Term 2012

Slide4

Part 1: doit

doit command:–Take another command line as argumentExecute that commandPrint out statistics about commandMust compile and execute on your virtual machineLikely to be compatible with most modern Linux systemsUseful system calls and functions:–fork(), execvp(), wait()getrusage(), gettimeofday()May not use system() system call

Project #1, Fork and Command Shell

4

CS-3013, C-Term 2012

Use

execvp

(), not

execve

()

Slide5

Part 1 (sample output

)% ./doit cat /etc/motd /* print the current message of the day */ /* statistics about the cat command */% ./doit

ls –l /

usr/src

/* list contents of the /

usr

/

src

directory */

/* statistics of the

ls

command */

% ./

doit

cp

–al /

usr

/

src

/linux-2.6.27.25-0.1

kernelSrc

/* output of the

cp

command (if any) */ /* statistics of the cp command */

Project #1, Fork and Command Shell

5

CS-3013, C-Term 2012

Slide6

doit Implementation Hint

Command line is already tokenized in argvStrip off the 0th element of argv vectorPass the remainder of argv to exec() for arguments of commandProject #1, Fork and Command Shell

6

CS-3013, C-Term 2012

Slide7

Questions?

CS-3013, C-Term 2012Project #1, Fork and Command Shell7

Slide8

Part 2: shell

Repeatedly prompt for command linesExecute each command and print out statistics, as in doitImplement special “built-in” commandsexitcd dir

Special conditionsInput from

stdinExit on end of fileComplain about illegal commands

Check for line length, number of arguments

Project #1, Fork and Command Shell

8

CS-3013, C-Term 2012

Slide9

Part 2 output

% shell==>cat /etc/motd /* print the current message of the day */ /* statistics about the cat command */==>cd dir /* current directory is changed to

dir */

==>ls –l /boot

/* listing of files in /boot directory */

/* statistics about this

ls

command */

==>exit

% /* back to your previous Linux prompt */

% shell < filename.txt

/* reads, echoes, and executes each command/*

/* statistics about each command */

/* exits after last command is completed */

Project #1, Fork and Command Shell

9

CS-3013, C-Term 2012

Slide10

shell Implementation Hints

Input command lineMay limit to 128 characters, 32 argumentsMust tokenize — use strtok() functionBuilt-in commands are not handled by fork and execMust be executed “in-line” in shell getrusage

() returns cumulative statisticsFor all children of this process

Must remember and subtract previous values to get statistics for most process most recently waited forProject #1, Fork and Command Shell

10

CS-3013, C-Term 2012

Slide11

Questions?

CS-3013, C-Term 2012Project #1, Fork and Command Shell11

Slide12

Part 3: Background Execution (

shell2)Modify shell to allow commands to execute in background, indicated by ‘&’ characterCauses shell to prompt for next command before previous command is completejobs built-in command lists background tasks in progressModified wait() callReturns immediately if nothing has terminated

Returns PID if any process has terminatedReport completion of command at next opportunity

I.e., the next time user types a command, or whenever wait() returns PID of the command

Project #1, Fork and Command Shell

12

CS-3013, C-Term 2012

Slide13

Part 3 output

% shell2==>make –j4 O=~/kernelDst &[1] 12345 /* indicate background task #1, process id */==>jobs[1] 12345 make /* print process id and command name for tasks */==>ls

/* listing of files in the current directory */

/* statistics about this ls command */

==>cat /

etc

/

motd

[1] 12345 make Completed

/* statistics about background job */

/* print the current message of the day */

/* statistics about this cat command */

==>exit

% /* back to your previous Linux prompt */

Project #1, Fork and Command Shell

13

CS-3013, C-Term 2012

Slide14

shell2 Implementation Hints

Use wait3() to Wait for any processWait without blocking – WNOHANG optionGet usage information directlyAfter fork(), shell2 does

while (pid

= wait3(WNOHANG)) {print msg

& statistics of

pid

update list of outstanding tasks

}

if

(latest not background &&

latest not done)

wait3(

latest_pid

);

else get next command;

Project #1, Fork and Command Shell

14

CS-3013, C-Term 2012

Slide15

Work environment

Program in CEven though it could easily be done in C++Project can be carried out on any Linux systemE.g., your own or corporate environmentWe will grade it on openSUSE 11.4 I.e., your virtual machine environmentNote:Linux systems are often compatible with each otherHowever, not all C/C++ compilers and Linux kernels are alikeSome may produce or ignore compiler warningsYour virtual machine is the one that counts

Project #1, Fork and Command Shell

15

CS-3013, C-Term 2012

Slide16

Project submission

Due Sunday, January 22 @ 11:59 PMSubmit via web-based TurninProject name = Project 1Put your name at top of every file!(You would be surprised how many students forget!)Project #1, Fork and Command Shell16CS-3013, C-Term 2012

Slide17

Project Submission (continued

)Code of your solutionA single Makefilemake allmake doitmake shell

make shell2

make cleanTest cases for each part

Write-up explaining everything

Especially how

to keep

track of outstanding processes in

shell2

Zip

everything together

DO NOT

Put different parts of project in separate folders

Use different

makefiles

for different

parts of

project

Project #1, Fork and Command Shell

17

CS-3013, C-Term 2012

DO NOT create

.

rar

,

.

gz

,

.tar

, etc. files

Only

.zip

files are acceptable

Slide18

Grading

Ten point projectPart 1 – 2 pointsPart 2 – 3 pointsPart 3 – 4 pointsPoint allocation per partSee printed project descriptonWrite-up explaining what you did and your results1 pointMS Word or PDFNo credit for a part if it fails to buildProject #1, Fork and Command Shell18

CS-3013, C-Term 2012

Slide19

Not a team project!

Each student must submit own solutionEncouraged to discuss general approach, meaning of system calls, etc., with friendsEncouraged to seek help if puzzled by some concept, system call, etc.Distill all discussions into your own work!Project #1, Fork and Command Shell19CS-3013, C-Term 2012

Slide20

Questions?

CS-3013, C-Term 2012Project #1, Fork and Command Shell20


About DocSlides
DocSlides allows users to easily upload and share presentations, PDF documents, and images.Share your documents with the world , watch,share and upload any time you want. How can you benefit from using DocSlides? DocSlides consists documents from individuals and organizations on topics ranging from technology and business to travel, health, and education. Find and search for what interests you, and learn from people and more. You can also download DocSlides to read or reference later.