Unix Processes. What is a Process?

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

5/8/2012. Controlling User Processes Chapter 10

Bamuengine.com. Chapter 7. The Process

Operating System Labs. Yuanbin Wu

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

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

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

Design Overview of the FreeBSD Kernel CIS 657

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent?

Chap 4, 5: Process. Dongkun Shin, SKKU

ENGR 3950U / CSCI 3020U Midterm Exam SOLUTIONS, Fall 2012 SOLUTIONS

Sperimentazioni I LINUX commands tutorial - Part II

(MCQZ-CS604 Operating Systems)

Linux System Administration

Lab 2: Implementing a Shell COMPSCI 310: Introduction to Operating Systems

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

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

Operating System Structure

Assignment 1. Teaching Assistant: Michalis Pachilakis (

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

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

Process Management 1

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

Process Management! Goals of this Lecture!

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

System Programming. Introduction to Unix

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

Chapter 3: Process Concept

Chapter 3: Process Concept

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Chapter 3: Process Concept

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

S E C T I O N O V E R V I E W

Processes COMPSCI 386

CSE 410: Computer Systems Spring Processes. John Zahorjan Allen Center 534

Processes. CS3026 Operating Systems Lecture 05

The Classical OS Model in Unix

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

bash, part 3 Chris GauthierDickey

Computer Systems II. First Two Major Computer System Evolution Steps

Introduction to UNIX Shell Exercises

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

Linux shell scripting Getting started *

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

SOFTWARE ARCHITECTURE 3. SHELL

System Administration

M2PGER FORTRAN programming. General introduction. Virginie DURAND and Jean VIRIEUX 10/13/2013 M2PGER - ALGORITHME SCIENTIFIQUE

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)

Advanced Unix Concepts. Satyajit Rai

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476

Mon Sep 17, 2007 Lecture 3: Process Management

Review of Fundamentals

Chapter 3: Processes

Jan 20, 2005 Lecture 2: Multiprogramming OS

Command-line interpreters

CSE 153 Design of Operating Systems Fall 2018

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

UNIX Kernel. UNIX History

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

Operating Systems. Lecture 07. System Calls, Input/Output and Error Redirection, Inter-process Communication in Unix/Linux

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission 1

Linux Command Line Interface. December 27, 2017

OPERATING SYSTEMS: Lesson 4: Process Scheduling

Process Management! Goals of this Lecture!

CSC UNIX System, Spring 2015

Systems Programming/ C and UNIX

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009

CS370 Operating Systems

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

Lab 2: Linux/Unix shell

Announcement. Exercise #2 will be out today. Due date is next Monday

What is a Process. Processes. Programs and Processes. System Classification 3/5/2013. Process: An execution stream and its associated state

CPSC 457 OPERATING SYSTEMS MIDTERM EXAM

5/20/2007. Touring Essential Programs

Operating Systems. II. Processes

Multiprogramming. Evolution of OS. Today. Comp 104: Operating Systems Concepts 28/01/2013. Processes Management Scheduling & Resource Allocation

REVIEW OF COMMONLY USED DATA STRUCTURES IN OS

CS 201. Processes. Gerson Robboy Portland State University

COMP 3430 Robert Guderian

CST Algonquin College 2

ESE 333 Real-Time Operating Systems 2 What is an operating system? Two views: 1. Top-down view: Extended machine ffl Covers the details of the hardwar

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Midterm Exam CPS 210: Operating Systems Spring 2013

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

CSC209 Review. Yeah! We made it!

Problem Set: Processes

Processes. Dr. Yingwu Zhu

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

What is the Shell. Whenever you login to a Unix system you are placed in a program called the shell. All of your work is done within the shell.

Binghamton University. CS-220 Spring Sharing Resources. Computer Systems Chapter 8.2, 8.4

UNIX. Session 2. UNIX processes and forking fork system call exec system call death of process kill fork and I/O using it UNIX.

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

PROCESS CONTROL: PROCESS CREATION: UNIT-VI PROCESS CONTROL III-II R

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar

Transcription:

Unix Processes Process -- program in execution shell spawns a process for each command and terminates it when the command completes Many processes all multiplexed to a single processor (or a small number of CPUs i.e. multi-core) What is a Process? Abstraction of a running process. Consists of: an address space code, data and stack thread(s) of execution thread context (values of registers, PC, SP) misc. processor state (privilege) execution stack resources allocated to process open files and sockets attributes i.e. process ID 1

Multiprogramming OS provides an illusion of multiple processes concurrently executing -- only 1 CPU CPU is simply a resource for OS to manage allocate CPU to a process, allow it to run for a while (or until process blocks) and then assign CPU to another process repeat until process has had enough turns to complete it s task Context switch process of switching between processes by saving the state of the current running process to disk and bringing in the state of the next process to run Quantum - period of time that a process is assigned a CPU 50-200 ms OS uses a scheduling algorithm to select which process gets CPU next first-come first served round robin priority 2

Unix Process States During execution a process constantly changes states (assuming a single CPU system): Ready ready to run but doesn t have CPU usually many waiting in the ready queue Running The process is actually running (using the CPU). Blocked Idle waiting for an event to happed i.e.. a disk read to complete Swapped Ready to run but process image has been swapped out to disk to create space for other processes Zombie Process has completed its work and exited but it s parent isn t waiting for it. Eventually will be reclaimed and cleaned up by the system. 3

Process State Diagram Swapped Ready Running Blocked Zombie Process Hierarchy When OS starts up the first process created if the init process (/etc/init) granddaddy of all processes PID 1, privileged mode Performs system initialization and creates other processes getty process -- login 4

Execution of Shell Commands Internal vs. external commands internal handled by shell external shell spawns a new process embodying the command shell waits while command executes process structure is hierarchical A process can replicate itself via the fork system call exact duplicate of parents address space both parent (caller of fork) and child continue execution at the line after the fork call parent sh sh child fork 5

To spawn a different process the exec (execv) syscall is used fork and exec used in conjunction Consider a shell (sh) executing the ls command sh uses fork to replicate itself and then uses exec to overlay the image of the binary ls command sh waits while the ls command runs control returns to sh after ls completes Diagram of Shell Command Execution sh parent sh sh fork sh child ls exec(ls) 6

Execution of Shell Scripts Shell script sequence of commands in a file exactly as if they are entered on a keyboard Shell script execution spawns a child shell process to handle the script each command inside the script results in the creation of a new process child terminates at the End Of File (EOF) marker Diagram of Shell Script Execution sh parent sh parent sh fork sh child sh script file grep fork,exec(grep) 7

Process Attributes Information maintained for each process process id (PID) owner (users) ID process name state (ready, running, blocked, ) parent s PID running time Process Status The ps command reports the status of processes. For example, % ps Full listing of all of your processes: % ps -f UID PID PPID C STIME TTY TIME CMD jay 23375 23373 0 12:21:27 pts/20 0:06 -bash All running processes on the system % ps e 8

Process & Job Control User can control process state: creation, termination, running in the foreground & background, suspending, moving to foreground & background Foreground & Background Normal command execution % command <Enter> command runs while shell waits command controls keyboard, monitor A process can run in the background via % command & <Enter> shell separated from command runs with lower priority 9

Process Control Commands fg command brings a background process to the foreground Entering <ctrl-z> suspends a process Use the bg command to resume a suspended process jobs command displays status of your processes [522]% jobs [1]+ Stopped emacs -nw [2]- Running find / -name hello -print >outfile 2>/dev/null & [523]% fg 2 find / -name hello -print >outfile 2>/dev/null <ctrl-c> 10

Command Separators Sequential execution of commands: % command1; command2; command3 new process for each commands can be grouped to run inside the same process % (command1; command2; command3) Commands can also be executed in parallel in the background: % command1& command2& command3& Terminating Processes A process can be terminated via the kill command % kill PID Add 9 to definitely kill the process % kill 9 PID Consider, % ls PID TTY TIME CMD 18041 pts/18 0:04 bash 16070 pts/18 0:00 bash 16882 pts/18 0:07 emacs-21 % kill 16882 11

Long Running Processes When you logout all processes are terminated. What if you want something to run overnight? The nohup (No Hang UP) command enables a process to survive after logging out % nohup command runs at lower priority Redirection & Piping Typical command takes input, performs work and outputs results Where does it get input from? Output is displayed where? Where are errors reported? Unix sends input, output & errors to default locations Standard Files Can be redirected by user to connect commands together 12

Standard Files Three files automatically opened for each command: Standard Input (stdin) keyboard, data file, results of another command Standard Output (stdout) & Standard Error (stderr) screen/console, file stdout Keyboard Command Screen stdin stderr Input Redirection Input redirection is done via the < operator. For example, % command < input-file Overrides stdin to be input-file. Output and errors still go to screen What is the difference between these commands? % cat < tmpfile % cat tmpfile 13

Output Redirection The output of a command can be redirected with the > operator. For example, % command > output-file Detach screen from stdout and attach output-file to it. Output of command goes to output-file Error messages still directed to screen Consider, % cat > outfile Redirection of I/O can be combined. Consider, % cat < infile > outfile A table inside of each process records all files opened by the process (file descriptors) 3+ user defined stdin < or 0< stdout > or 1> 0 stdin 1 stdout 2 stderr 3 14

Error Redirection Standard error can be redirected by referring to the file descriptor 2> % command 2> error-file Input & output unchanged only error messages are redirected % cat file1 2> error.log % cat error.log % cat: error.log: No such file or directory Redirecting Everything All standard files can be redirected via % command 0< in-file 1> out-file 2> error-file Redirecting stdout and stderr to the same file $ command 1> script-file 2>&1 2>&1 make fd 2 to a duplicate of 1 >overwrites files to append to a file use >> 15

Unix Pipes The pipe operator sends stdout of one command to stdin of another. For example, % command1 command2 the output of command1 while be sent as input to command2 IPC mechanism Used to perform complex tasks I/O redirection cannot accomplish the same task in a single command. Consider, % ls la more Output is buffered in RAM not on a disk. Compare with % ls la > tmp; more tmp; rm tmp 16