Shells and Processes. Bryce Boe 2012/08/08 CS32, Summer 2012 B

Similar documents
Unix Processes. What is a Process?

Lecture 2: Processes. CSE 120: Principles of Opera9ng Systems. UC San Diego: Summer Session I, 2009 Frank Uyeda

Most of the work is done in the context of the process rather than handled separately by the kernel

Lab 2: Linux/Unix shell

Programs. Program: Set of commands stored in a file Stored on disk Starting a program creates a process static Process: Program loaded in RAM dynamic

Operating Systems. Copyleft 2005, Binnur Kurt

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

Linux System Administration

Chap2: Operating-System Structures

The Unix Shell & Shell Scripts

Introduction to Linux

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Linux Command Line Interface. December 27, 2017

Crash Course in Unix. For more info check out the Unix man pages -orhttp:// -or- Unix in a Nutshell (an O Reilly book).

Introduction to Linux

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

Systems Programming/ C and UNIX

Simplest version of DayOfYear

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

The UNIX Shells. Computer Center, CS, NCTU. How shell works. Unix shells. Fetch command Analyze Execute

Chapter 9: Process management. Chapter 9 Process management

Bamuengine.com. Chapter 7. The Process

UNIX. The Very 10 Short Howto for beginners. Soon-Hyung Yook. March 27, Soon-Hyung Yook UNIX March 27, / 29

Shells. A shell is a command line interpreter that is the interface between the user and the OS. The shell:

Processes. What s s a process? process? A dynamically executing instance of a program. David Morgan

Introduction to UNIX Shell Exercises

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Operating systems fundamentals - B02

Exploring UNIX: Session 5 (optional)

Assignment clarifications

Sperimentazioni I LINUX commands tutorial - Part II

Introduction to Linux. Fundamentals of Computer Science

Introduction to Linux

5/8/2012. Controlling User Processes Chapter 10

Welcome to Linux. Lecture 1.1

Advanced Unix Concepts. Satyajit Rai

CISC 220 fall 2011, set 1: Linux basics

Introduction to Linux

Mid Term from Feb-2005 to Nov 2012 CS604- Operating System

CS370 Operating Systems

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

3/8/2017. Unix/Linux Introduction. In this part, we introduce. What does an OS do? Examples

elinks, mail processes nice ps, pstree, top job control, jobs, fg, bg signals, kill, killall crontab, anacron, at

UNIX COMMANDS AND SHELLS. UNIX Programming 2015 Fall by Euiseong Seo

Processes. System tasks Campus-Booster ID : **XXXXX. Copyright SUPINFO. All rights reserved

Introduction to the Shell

Operating Systems Lab 1 (Users, Groups, and Security)

Command-line interpreters

CST Algonquin College 2

APPLIED INFORMATICS Processes. Bash characteristics. Command type. Aliases.

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

CSC UNIX System, Spring 2015

System Programming. Unix Shells

EECS2301. Lab 1 Winter 2016

LOG ON TO LINUX AND LOG OFF

Bash scripts. Marcus Holm. slides courtesy of: Douglas Scofield

Checking Resource Usage in Fedora (Linux)

University of Washington What is a process?

elinks, mail processes nice ps, pstree, top job control, jobs, fg, bg signals, kill, killall crontab, anacron, at

1 PartA. Lab#1 Solutions: COMP 3000A(Operating Systems) October 9, TheShell. 1.2 Help

UNIX Kernel. UNIX History

Introduction: What is Unix?

The Unix Shell. Job Control

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts

bash, part 3 Chris GauthierDickey

Study Guide Processes & Job Control

System Administration

Bourne Shell (ch 8) Overview. Bourne Shell. Bourne Shell. Bourne Shell. Bourne Shell. Redirect standard error. Redirect standard error

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

Perl and R Scripting for Biologists

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Processes and Shells

Lec 1 add-on: Linux Intro

A Brief Introduction to Unix

Processes in linux. What s s a process? process? A dynamically executing instance of a program. David Morgan. David Morgan

Operating Systems. Lecture 05

GNU/Linux Course Lesson 1. Puria Nafisi

27-Sep CSCI 2132 Software Development Lab 4: Exploring bash and C Compilation. Faculty of Computer Science, Dalhousie University

Introduc)on to Linux HPC Workshop

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

Useful Unix Commands Cheat Sheet

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 1

Introduction to Linux

unix intro Documentation

History. Terminology. Opening a Terminal. Introduction to the Unix command line GNOME

CRUK cluster practical sessions (SLURM) Part I processes & scripts

Implementation of a simple shell, xssh

Chap 4, 5: Process. Dongkun Shin, SKKU

Implementation of a simple shell, xssh

EKT332 COMPUTER NETWORK

5/20/2007. Touring Essential Programs

Opera&ng Systems ECE344

Review of Fundamentals

(MCQZ-CS604 Operating Systems)

Managing Processes Process: A running program

Creating a Shell or Command Interperter Program CSCI411 Lab

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Mauro Ceccanti e Alberto Paoluzzi

Introduction to Unix: Fundamental Commands

Computer Systems and Architecture

Transcription:

Shells and Processes Bryce Boe 2012/08/08 CS32, Summer 2012 B

Outline Opera>ng Systems and Linux Review Shells Project 1 Part 1 Overview Processes Overview for Monday (Sor>ng Presenta>ons)

OS Review Opera>ng systems Manages system resources: cpu, memory, I/O Types: single/mul>- user and single/mul>- process Provides fairness, security

Self Check Ques>ons What is the primary benefit of a mul>- process OS over a single process OS? How is this accomplished? Explain the difference between mul>programming and mul>tasking

Self Check Answers What is the primary benefit of a mul>- process OS over a single process OS? How is this accomplished? Increased resource u>liza>on (primarily of the CPU) accomplished by scheduling other processes when the currently running process requires I/O

Self Check Answers cont. Explain the difference between mul>programming and mul>tasking Mul>programming systems switch the running process when that process requires I/O. Mul>tasking systems periodically switch the running process a\er some (typically minute) period of >me

Linux Architecture

Shells

What is a shell? A shell is a program that provides the interface between the user and the opera>ng system Can be used to tell the OS to: Execute programs (as processes) Stop, or pause processes Create, copy, move, remove files Load or unload device drivers

Types of Shells Command line shells: Provide a textual input as the user- interface Bourne shell (sh), C shell (csh), Bourne- Again shell (bash), cmd.exe Graphical shells Provide a point- and- click type interface Windows shell, Gnome, KDE, Xfce, Xmonad

Login Shell The shell presented to the user upon login Typically changeable on Linux via chsh

Configura>on Files Unix shells typically load configura>on sebngs on launch Bourne shell: ~/.profile C shell: ~/.login, ~/.cshrc Bash: ~/.bashrc, ~/.bash_profile Useful to adjust environment variables such as the PATH Examples are provided in the reader on page 29 and 30

Unix Shells Contain built- in commands cd, eval, exec, exit, pwd, test, umask, unset Launch external programs cat, cp, mv, touch, wc Con>nue execu>ng un>l their input stream is closed via <ctrl+d> External commands are searched for according to the PATH environment variable

Launching shells Shells can be launched within shells (they re just applica>ons a\er- all) Demo pstree with nested shells Shells process commands from stdin Run: echo "echo foo" sh Combined with stdin redirec>on we have the ability to write shell scripts More on shell scripts in lab1 and project 1

Working with the PATH The PATH environment variable specifies directories containing executable file Commands to demo: echo $PATH which - a <PROG_NAME> Bad things can happen with. is on the PATH Shell script wrapper program

Shell meta characters Support for globbing Filename expansion using: * - wildcard to match 0 or more characters? wildcard to match exactly one character [ ] matches one character if it s contained in the character list [0-9A- Za- z] will match a single character if it s alphanumeric Home directory subs>tu>on via ~

Project 1 Part 1 Automated tes>ng bourne script Usage: test_it.sh DIRECTORY Given a directory as input run tests against programs specified by DIRECTORY s subdirectory names Individual test inputs are files prefixed with input_ and should be compared with the corresponding output_ file

DIRECTORY Hierarchy Execute:./test_it.sh test_root input_test_a input_test_b prog_name/ output_test_a test_root/ output_test_b input_a another_prog_name/ output_a

Project 1 Part 1 Demo

Processes (in Linux) A process is a program in execu>on Copied to memory and assigned a process ID (PID) Mul>ple processes run simultaneously via mul>tasking Processes are created when an exis>ng process makes a fork or clone system call Processes can have different scheduling priority (nice values in Linux)

Simple Fork Example

Running sort from bash

Running a shell script that runs find exec

Select Process Awributes The column names as listed in ps -l output S the state of the process PID the process id PPID the parent process id UID process owner s user id WCHAN the event a non- running process is wai>ng for

Process Hierarchy init (now systemd) is the root of all processes (PID 1) The process hierarchy's depth is limited only by available virtual memory A process may control the execu>on of any of its descendants Can suspend or resume it Can even terminate it completely By default, termina>ng a process will terminate all of its descendants too So termina>ng the root process will terminate the session

Example Process Hierarchy

Process States A process exist in a number of different states Ready The process is ready to be scheduled Running The process is currently runny Swapped Part or all of the process s memory is on disk Zombie The parent of the process no longer exists

Process States Diagram

ps Observing Process States and Hierarchy Output a snapshot of the running process (many op>ons) pstree top Output a text- based view of the process hierarchy tree A terminal- based process monitoring program

Process Exit Status Each process exits with some status 0-255 0 is typically used to indicate success All other numbers are used to indicate some error condi>on that is applica>on specific In C/C++ the int return value from the main is the exit status

Processes and the shell The shell can run processes in the foreground (fg) and the background (bg) Mul>ple processes can be run in succession or in parallel via a single command

Foreground and background The shell normally runs processes in the foreground Launch a process in the background via & sleep 500 & See a list of background processes (jobs) associated with your current shell via jobs

Background - > foreground Type: fg (note there must be a background processes running) You can also explicitly foreground a specific job by number: fg %3

Foreground - > background When a process is running, suspend it: <ctrl> + z This will bring you back to the terminal Then run bg to resume the process running in the background As with the fg command, you can provide an explicit job number: bg %2

Sequen>ally execu>ng programs Separate via ; on the command line sleep 5; ls; sleep 5; ls Processes run regardless of previous process s exit status Condi>onally execute sequen>ally based on exit status: separate via && sleep 5 && ls - l foo && sleep 5 && ls l Command stops when a non- zero exit status is returned

Execu>ng programs in parallel Separate via &, the background process indicator echo foo & echo bar & echo somethingelse & If process is running in the background, the command s exit status will be zero

Mix and match sleep 5; echo foo& echo bar & ; ls sleeps 5 seconds Concurrently runs echo foo, echo bar and ls Both echo commands run in the background ls runs in the foreground

For Monday Prepare 10-15 minute presenta>on on an assigned sor>ng algorithm Provide a number of examples and detail and possible corner cases 1 volunteer will be asked to present each sor>ng algorithm If no volunteers, then someone will be picked randomly Complete instruc>ons will be posted on Piazza some>me before Thursday s lab