Dsh: A Devil Shell COMPSCI210 Recitation 14 Sep 2012 Vamsi Thummala.

Slides:



Advertisements
Similar presentations
Recitation 8 (Nov. 1) Outline Process & job control Lab 5 Reminder Lab 5: Due Thursday Minglong Shao Office hours: Thursdays 5-6PM.
Advertisements

3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process An operating system executes a variety of programs: Batch system.
Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.
15-213, Fall 06 Outline Shell Lab Processes Signals.
Process groups, sessions, controlling terminal, and job control Process relationship: –Parent/child –Same group –Same session.
Process Relationships Terminal and Network Logins Process Groups and Sessions Job Control Relationships.
UC Santa Barbara Project 1 Discussion Bryce Boe 2011/04/12.
1 Processes Professor Jennifer Rexford
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
1 Processes and Pipes. 2 "He was below me. I saw his markings, manoeuvred myself behind him and shot him down. If I had known it was Saint-Exupery, I.
Process Control in Unix Operating Systems Hebrew University Spring 2004.
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
CSSE Operating Systems
Fork and Exec Unix Model Tutorial 3. Process Management Model The Unix process management model is split into two distinct operations : 1. The creation.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
Process Control. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor utilization while providing.
The Programming Interface. Main Points Creating and managing processes – fork, exec, wait Performing I/O – open, read, write, close Communicating between.
Unix Processes Slides are based upon IBM technical library, Speaking Unix, Part 8: Unix processes Extended System Programming Laboratory (ESPL) CS Department.
Shell (Part 1). Process r A process is an instance of an application running r If there are two instances of an application running then there are two.
Unix Pipes Pipe sets up communication channel between two (related) processes. 37 Two processes connected by a pipe.
The Classical OS Model in Unix. Nachos Exec/Exit/Join Example Exec parentExec child Join Exit SpaceID pid = Exec(“myprogram”, 0); Create a new process.
Today’s Topics Introducing process: the basic mechanism for concurrent programming –Process management related system calls Process creation Process termination.
Recitation 9: Section L (1:30pm - 2:20pm) Monday, October 22, 2012 Processes, Signals and Shell Lab Siddharth Dhulipalla.
Cli/Serv.: procs/51 Client/Server Distributed Systems v Objectives –look at how to program UNIX processes , Semester 1, Processes.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
Shell (Part 2). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
Creating and Executing Processes
Pipes A pipe is a simple, synchronized way of passing information between processes A pipe is a special file/buffer that stores a limited amount of data.
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
Lecture Thread: Unix process-oriented system calls
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 8: Opening Files and Starting Processes.
CS162B: Pipes Jacob T. Chan. Pipes  These allow output of one process to be the input of another process  One of the oldest and most basic forms of.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Agenda  Redirection: Purpose Redirection Facts How to redirecting stdin, stdout, stderr in a program  Pipes: Using Pipes Named Pipes.
Shell (Addendum). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
Unix Process Model Simple and powerful primitives for process creation and initialization. fork syscall creates a child process as (initially) a clone.
Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes.
Operating Systems Process Creation
1 Tutorial: CSI 3310 Dewan Tanvir Ahmed SITE, UofO.
CSCI 330 UNIX and Network Programming Unit XII: Process & Pipe Part 1.
Recitation: Signaling S04, Recitation, Section A Debug Multiple Processes using GDB Debug Multiple Processes using GDB Dup2 Dup2 Signaling Signaling.
Process Management Azzam Mourad COEN 346.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
Chapter 1 Introduction  What is an operating system  History of operating systems  The operating system zoo  Computer hardware review  Operating system.
CSCI 330 UNIX and Network Programming
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.
OS Labs 2/25/08 Frans Kaashoek MIT
Tutorial 3. In this tutorial we’ll see Fork() and Exec() system calls.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
1 Unix system calls fork( ) wait( ) exit( ). 2 How To Create New Processes? n Underlying mechanism -A process runs fork to create a child process -Parent.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
4.1 Operating Systems Lecture 9 Fork and Exec Read Ch
Process Related System Calls By Neha Hulkoti & Kavya Bhat.
1 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430.
The Shell What does a shell do? - execute commands, programs - but how? For built in commands run some code to do the command For other commands find program.
Unix Process Management
Chapter 3: Processes.
Fork and Exec Unix Model
System Structure B. Ramamurthy.
Pipes A pipe provides a one-way flow of data example: who | sort| lpr
LINUX System Programming with Processes (additional)
2/25/08 Frans Kaashoek MIT OS abstractions 2/25/08 Frans Kaashoek MIT
Process Creation Process Termination
Tutorial 3 Tutorial 3.
Programming Assignment # 2 – Supplementary Discussion
Process Programming Interface
IPC Prof. Ikjun Yeom TA – Hoyoun
Today’s topic UNIX process relationship and job control
Processes, Unix, and IPC.
System Programming: Process Management
Presentation transcript:

dsh: A Devil Shell COMPSCI210 Recitation 14 Sep 2012 Vamsi Thummala

Comments on heap manager Q's on pointer manipulation Infinite loop Space utilization (success rate) segfault issues

The fact Debugging segfaults is hard! gdb can help Code walk through is often faster (for this lab)

Shell Interactive command interpreter A high level language (scripting) Interface to the OS Provides support for key OS ideas –Isolation –Concurrency –Communication –Synchronization

Demo

Unix programming environment stdout stdin Standard unix programs read a byte stream from standard input (fd==0). They write their output to standard output (fd==1). That style makes it easy to combine simple programs using pipes or files. If the parent sets it up, the program doesn’t even have to know. Stdin or stdout might be bound to a file, pipe, device, or network socket.

Shell Concepts Process creation Execution Input/Output redirection Pipelines Job control –Process groups –Sessions –Foreground/background jobs Given that many processes can be executed concurrently, which processes should have accesses to the keyboard/screen (I/O)? –Signals SIGSEGV (segfault), SIGINT, SIGCONT

Unix fork/exec/exit/wait syscalls fork parentfork child wait exit int pid = fork(); Create a new process that is a clone of its parent. exec*(“program” [, argvp, envp]); Overlay the calling process with a new program, and transfer control to it. exit(status); Exit with status, destroying the process. Note: this is not the only way for a process to exit! int pid = wait*(&status); Wait for exit (or other status change) of a child, and “reap” its exit status. Note: child may have exited before parent calls wait! exec initialize child context

Process creation and execution while (1) { printf(“$”); command = readnparse(args); switch (pid = fork()) { // new process; concurrency case -1: perror(“Failed to fork\n”); case 0: // child when pid = 0 exec (command, args, 0); // run command default: // parent pid > 0 waitpid(pid, NULL, 0); // wait until child is done }

Input/Output (I/O) I/O through file descriptors – File descriptor may be for a file, terminal, … Example calls – read(fd, buf, sizeof(buf)); – write(fd, buf, sizeof(buf)); Convention: – 0: input – 1: output – 2: error Child inherits open file descriptors from parents

I/O redirection ( ) Example: “ls > tmpFile” Modify dsh to insert before exec: close(1); // release fd 1 fd = create(“tmpFile”, 0666); // fd will be 1 No modifications to “ls”! “ls” could be writing to file, terminal, etc., but programmer of “ls” doesn’t need to know

Pipeline: Chaining processes One-way communication channel Symbol: | int fdarray[2]; char buffer[100]; pipe(fdarray); write(fdarray[1], “hello world”, 11); read(fdarray[0], buffer, sizeof(buffer));

Pipe between parent/child int fdarray[2]; char buffer[100]; pipe(fdarray); switch (pid = fork()) { case -1: perror(“fork failed”); case 0: write(fdarray[1], "hello world", 5); default: n = read(fdarray[0], buffer, sizeof(buffer)); //block until data is available } How does the pipes in shell, i.e, “ls | wc”? dup2(newfd, oldfd); // duplicates fd; closes and copies at one shot

Process groups –A process group is a collection of (related) processes. Each group has a process group ID. –Each group has a group leader who pid = pgid –To get the group ID of a process: pid_t getpgrp(void) –A process may join an existing group, create a new group. int setpgid(pid_t, pid, pid_t, pgid) – A signal can be sent to the whole group of processes.

pid_t spawn_job(bool fg, pid_t pgrp) { int ctty = -1; pid_t pid; switch (pid = fork()) { case -1: /* fork failure */ return pid; case 0: /* child */ /* establish a new process group, and put the child in * foreground if requested * Q: what if setpgid fails? */ if (pgrp < 0) pgrp = getpid(); if (setpgid(0,pgrp) == 0 && fg) // If success and fg is set tcsetpgrp(ctty, pgrp); // assign the terminal return 0; default: /* parent */ /* establish child process group here too. */ if (pgrp < 0) pgrp = pid; setpgid(pid, pgrp); return pid; }