Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 ....

19
Project #1: Command-Line User Interface Shell and Utilities

Transcript of Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 ....

Page 1: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

Project #1: Command-Line User Interface Shell

and Utilities

Page 2: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

Outline

• Background

• General Requirements/Assumptions

• Implementation Tools

• Details

• Questions

Page 3: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

Operating Systems

• Provides resources and services

– Examples

• High-level interactions with user

• Protection mechanisms (e.g., process model)

• Processor scheduling

• Synchronization (Serialization) of executing code

• Filesystem

Project #1

Project #2

Project #3

Page 4: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

OS

Base System

inp

ut

ou

tpu

t

HW

Page 5: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

Command-Line Shell

• Provides means for user to interact with OS

– View/modify state of the system

• Simple and easy to use

• Considered a component of the OS

Page 6: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

Requirements

• User prompt • “built-in” utilities (Execute utility directly without

searching for it) – cd – ioacct – exit

• Start the execution of programs – background

• I/O redirection • input • output • pipelining

Page 7: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

Assumptions/Requirements

• Program written in C

• Makefile to build program

• No zombie processes

• No memory leaks

Page 8: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

IMPLEMENTATION TOOLS

Page 9: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

gcc Compiler

• Warnings are your friend and you don’t ignore your friends (most of the time)

• Useful gcc options – Wall

– Wextra

– pedantic

– Wconversion

– Wshadow

– std=c11 or -std=c99

Page 10: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

Makefile

• Targets – Name of file

– Name of an action

• Prerequisites – File/action that target depends on

– E.g., Source code files to create executable

• Recipe – Actions to create target file or satisfy named

action

target(s) : dependency(ies)

<tab>recipe

...

Page 11: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

PROJECT DETAILS

Page 12: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

Prompt

<username>@<hostname>:<working_directory> $

Example:

cop4610t@linprog:/home/grads/cop4610t $

Page 13: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

I/O Redirection

Text Terminal

Process

Keyboard

Display

Page 14: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

I/O Redirection

Text Terminal

Process

Keyboard

Display

FILEA

FILEB

Page 15: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

Redirect

FILEA open()

returns file descriptor

STDOUT_FILENO Process

dup2(fd_A, STDOUT…)

Display

fd_A

Page 16: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

File Descriptors

Kernel

File Descriptor Table (per-process)

ptr to terminal i/p

pointer to file A

ptr to terminal o/p

pointer to file A

<empty>

Page 17: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

File Descriptors

File Descriptor Table (per-process)

ptr to terminal i/p

pointer to file A

ptr to terminal o/p

pointer to file A

<empty>

Kernel Open File Table

# Off-set … inode

Page 18: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

Protection

Kernel Space

User Space

dup2()

Page 19: Project #1: Command-Line User Interface Shell and Utilities · Project #1 Project #2 Project #3 . OS Base System t put HW . Command-Line Shell ... B . Redirect FILE A open() returns

QUESTIONS?