Project 1 – My Shell Let’s get started… Alex Milenkovich.

Slides:



Advertisements
Similar presentations
Recitation 8: 10/28/02 Outline Processes Signals –Racing Hazard –Reaping Children Annie Luo Office Hours: Thursday 6:00.
Advertisements

More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Christo Wilson Project 2: User Programs in Pintos
Project 2 - Tasking.
CS 450 Module R1. R1 Introduction In Module R1, you will implement a user interface (command handler). There are a couple of options: ▫Command Line: interface.
Lecture 20 Arrays and Strings
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Input and Output CS 215 Lecture #20.
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
Exception Handling The purpose of exception handling is to permit the program to catch and handle errors rather than letting the error occur and suffer.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 14 - Advanced C Topics Outline 14.1Introduction.
The Environment of a UNIX Process. Introduction How is main() called? How are arguments passed? Memory layout? Memory allocation? Environment variables.
Introduction to C Programming
Programming Logic and Design Fourth Edition, Introductory
15-213/ Intro to Computer Systems by btan with reference to Spring 10’s slides.
Chapter 5 Processes and Threads Copyright © 2008.
Operating Systems Course Hebrew University Spring 2007 Signals & User Thread.
OCT 1 Master of Information System Management Organizational Communications and Distributed Object Technologies Lecture 5: Distributed Objects.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
BYU CS 345Chapter 3 - Processes1 Today… Lab 1 due tomorrow Early pass-off today Finish up with Implement the following shell commands: Add – add all numbers.
C Programming. C vs C++ C syntax and C++ syntax are the same but... C is not object oriented * There is no string class * There are no stream objects.
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
Chapter 4: Threads Adapted to COP4610 by Robert van Engelen.
UNIX Signals Bach 7.2 Operating Systems Course The Hebrew University Spring 2010.
Project 2 Data Communication Spring 2010, ICE Stephen Kim, Ph.D.
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
1Reference “Introduction To Unix Signals Programming” in the reference material section Man page – sigprocmask, alarm “Understanding the Linux Kernel”
Recitation 9: Section L (1:30pm - 2:20pm) Monday, October 22, 2012 Processes, Signals and Shell Lab Siddharth Dhulipalla.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 6 System Calls OS System.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
Lecture 24CS311 – Operating Systems 1 1 CS311 – Lecture 24 Outline Final Exam Study Guide Note: These lecture notes are not intended replace your notes.
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
4.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Project1: Unix Shell with History Feature Goals Descriptions Methodology Submission.
RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Operating Systems Process Creation
1 Signals (continued) CS 241 April 9, 2012 University of Illinois.
UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *
Fall 2002 CS 325 Class Notes Page 1 Lecture 25 Today –exec() in Unix –CreateProcess in Windows Announcements.
Lab 1 due Thursday Early pass-off Wednesday Finish up with Implement the following shell commands: Add – add all numbers in command line (decimal or hexadecimal).
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
S -1 Processes. S -2 wait and waitpid (11.2) Recall from a previous slide: pid_t wait( int *status ) wait() can: (a) block; (b) return with status; (c)
The Process CIS 370, Fall 2009 CIS UMassD. The notion of a process In UNIX a process is an instance of a program in execution A job or a task Each process.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
User-Written Functions
Microprocessor Systems Design I
A bit of C programming Lecture 3 Uli Raich.
Protection of System Resources
Command line arguments
Command Line Arguments
Chapter 4: Threads.
Unix Process Management
C Basics.
What is Bash Shell Scripting?
Project1: Unix Shell using Multi-Processing
Chapter 14 - Advanced C Topics
Tutorial: The Programming Interface
Processes in Unix, Linux, and Windows
Presentation transcript:

Project 1 – My Shell Let’s get started… Alex Milenkovich

1.1 Compile and Validate A task is a unit of execution (also referred to as a process). A shell (Command Language Interpreter) is a task that functions as an interface between the user and an Operating System. A shell interprets textual commands coming either from the user’s keyboard or from a script file and executes the commands either directly or creates a new child process to execute the command. For Project 1: Download all the project files from class website. os345.c, os345interrupts.c, os345signals.c os345tasks.c, os345semaphores.c os345.h, os345config.h, os345signals.h os345p1.c, os345p2.c, os345p3.c, os345p4.c, os345p5.c, os345p6.c os345park.c, os345park.h, os345lc3.c, os345lc3.h, os345mmu.c, os345fat.c, os345fat.h Edit os345config.h (if necessary) to select host OS/IDE/ISA. (Only enable one of the following defines: DOS, GCC, MAC, or NET.) Compile and execute your OS. BYU CS 345 Project 1 - Shell

1.2 Malloc/free argc/argv Command-line Arguments 1.2 Malloc/free argc/argv All tasks functions (main) are passed two arguments: The first (conventionally called argc, for argument count) is the number of command-line arguments (including the program name). The second (argv, for argument vector) is a pointer to an array of character pointers (strings) that contain the arguments, one per string. By convention, argv[0] points to the program name and argv[argc] is a null pointer. Modify the function P1_shellTask() (os345p1.c) to parse the commands and parameters from the keyboard inbuffer string into traditional argc and malloc'd argv C variables: Your shell executes the command directly using a function pointer with malloc’d arguments, waits for the function to return, and then recovers memory (free) before prompting for the next command. Commands and arguments are case insensitive. Quoted strings are treated as one argument and case is preserved within the string. BYU CS 345 Project 1 - Shell

1.3 Background Tasks Implement background execution of programs: If the command line ends with an ampersand (&), your shell creates a new task to execute the command line. (Otherwise, your shell calls the command function (and waits for the function to return.) Use the createTask function to create a background process. int createTask(char* name, // task name int (*task)(int, char**), // task address int priority, // task priority int argc, // task argument count char** argv) // task argument point The command arguments are passed to the new task in malloc'd argv strings. Modify the function createTask (os345tasks.c) to malloc new argc and argv variables. Modify the function sysKillTask (also in os345tasks.c) to recover malloc'd createTask memory. BYU CS 345 Project 1 - Shell

1.4 Signals A signal is an asynchronous notification of an event that is sent to a process before it is rescheduled for execution. Blocked processes are not un-blocked by a signal, but rather the signal remains pending until such time as the process is un-blocked and scheduled for execution. Before a task is scheduled by the function dispatcher (os345.c), the function signals (os345signals.c) is called: Modify the function signals (os345signals.c) to call all pending task signal handlers. Modify the function createTaskSigHandlers (os345signals.c) such that a child task inherits all its parent signal handlers. Modify the function sigAction (os345signals.c) to register new task signal handlers. Add default signal handlers as needed. Implement all signals and signal handlers such that: Cntrl-X terminates (kills) all tasks except task 0 (shell). Cntrl-W pauses the execution of all tasks. Cntrl-R continues the execution of all tasks after a pause. BYU CS 345 Project 1 - Shell

1.5 Finishing up… Implement the following shell commands: Add – add all numbers in command line (decimal or hexadecimal). Args – list all parameters on the command line, numbers or strings. (Bonus) Add additional functionality to your Shell such as: Command line recall of one or more previous commands. Help implemented using the “more” filter. Be able to edit command line (insert / delete characters). Chain together multiple commands separated by some delimiter. List / Set command line variables for aliasing. Calculator – perform basic binary operations. Date/Time – output current system date and time. Help – list all user commands and the syntax of their arguments. Help should be selective and have at least two levels of hierarchical depth. (Bonus) Command line recall/edit BYU CS 345 Project 1 - Shell

File Summary… Files needing attention: Event Handlers os345tasks.c – createTask, sysKillTask os345interrupts.c – keyboard_isr os345signals.c – signals, sigAction, sigSignal, defaultSigxxHandler, createTaskSigHandlers os345p1.c – P1_shellTask, P1_help … os345.h – your equates Event Handlers int signals(void); int sigAction(void (*sigHandler)(void), int sig); int sigSignal(int taskId, int sig); void defaultSigxxxHandler(void); void createTaskSigHandlers(int tid) BYU CS 345 Project 1 - Shell

Event-driven programming Event-driven programming is a programming paradigm in which the flow of the program is determined by sensor outputs, user actions (mouse clicks, key presses), or messages from other programs or threads. interrupts Application has a main loop Event selection (scheduler). Event handling (dispatcher). Events are external to a task Signals are asynchronous events Occur anytime, handled by call-back functions Semaphores are synchronous events. Occur anytime, handled by semaphores BYU CS 345 Project 1 - Shell

Signals New Ready Running Exit Signals Dispatcher calls signal handlers before rescheduling task: void mySIGINTHandler(void) void mySIGTERMHandler(void) { sigSignal(-1, SIGTERM); { killTask(curTask); return; return; } } keyboard_isr() detects a cntrl-X and sends a SIGINT signal to the shell: sigSignal(0, SIGINT); Task registers call-back signal handler functions with the OS: sigAction(mySIGINTHandler, SIGINT); sigAction(mySIGTERMHandler, SIGTERM); dispatch() createTask() killTask() New Ready Running Exit createTask calls createTaskSigHandlers() to setup default / parent signal handlers: void createTaskSigHandlers(int tid) { tcb[tid].sigIntHandler = defaultSigIntHandler; tcb[tid].sigTermHandler = defaultSigTermHandler; return; } SWAP BYU CS 345 Project 1 - Shell

Signals Signal Handling BYU CS 345 Project 1 - Shell

Keyboard Interrupts Keyboard Input Action Cntrl-X sigSignal SIGINT to shell Clear input buffer semSignal inBufferReady Cntrl-R sigSignal SIGCONT to all tasks Clear SIGSTOP from all tasks Clear SIGTSTP from all tasks Cntrl-W sigSignal SIGTSTP to all tasks BYU CS 345 Project 1 - Shell

Grading Criteria… There are 7 points possible for Lab 1: 2 pts – Your shell parses the command line into argc and malloc'd argv argument variables. Function createTask() malloc’s and copies argv argument variables as well. All malloc'd memory is appropriately recovered by sysKillTask(). 1 pt – Commands and arguments are case insensitive. Quoted strings are treated as one argument and case is preserved within the string. Backspace is implemented (delete character to the left) and correctly handles input buffer under/overflow. 2 pts – The signals SIGCONT, SIGINT, SIGTSTP, SIGTERM, and SIGSTOP function properly as described. 1 pt – The required shell commands add and args are correctly implemented. (The add command handles hexadecimal as well as decimal arguments.) 1 pt – Your shell supports background execution of all commands. In addition, the following bonus/penalties apply: +1 pt – Early pass-off (at least one day before due date.) +1 pt – An additional shell function of your choice is implemented. +2 pts – Implementing command line recall. -1 pt – Each school day late. BYU CS 345 Project 1 - Shell

Miscellaneous… Written in C (not C++) Shell commands are C functions. Project 1 Miscellaneous… Written in C (not C++) Shell commands are C functions. Arguments parsed into traditional C argc and malloc'd argv variables. Support background execution of command programs (& at the end of the line). Keyboard polled (pollInterrupts) during the scheduling loop. Before a process is scheduled/dispatched, properly handle any pending signals. SWAP macros liberally placed throughout your code. Handle strings, quoted strings, decimal numbers, or hexadecimal numbers. Commands may be terse and/or verbose (ie, ls and list). Some extended form of on-line help is required. Define argument delimiters, command delimiters, and address case sensitivity issues. Make your shell scalable. BYU CS 345 Project 1 - Shell Alex Milenkovich 13

Event-driven programming Batch version read a number (from the keyboard) and store it in variable A[0] read a number (from the keyboard) and store it in variable A[1] print A[0]+A[1] Event-driven version k = 0; while (1) { if ( c = getCharacter() ) { A[k++] = c; if (k == 2) { print A[0]+A[1]; } BYU CS 345 Project 1 - Shell

Command-line Arguments By standards, argv[argc] is a null pointer. Must be malloc’d echo\0 hello\0 world\0 argv: // echo command-line arguments int main(int argc, char* argv[ ]) { while (--argc > 0) printf("%s%s", *++argv, (argc > 1) ? " " : ""); printf("\n"); return 0; } BYU CS 345 Project 1 - Shell