Chapter 13 Processes.

Slides:



Advertisements
Similar presentations
June 1, 1999Foreground/Background Processing1 Introduction to UNIX H. Foreground/Background Processing.
Advertisements

Using tcpdump. tcpdump is a powerful tool that allows us to sniff network packets and make some statistical analysis out of those dumps. tcpdump operates.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process The Process A process is.
Chapter 13 Processes. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Objectives To describe the concept of a process, and execution of.
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
1 Introduction to UNIX Ke Liu
Chapter 13 Processes. What is a process? A process is a program in execution A process is created whenever an external command is executed Whenever the.
Shells and Processes Bryce Boe 2012/08/08 CS32, Summer 2012 B.
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
Linux+ Guide to Linux Certification, Second Edition
Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes.
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
Processes & Daemons Chapter IV / Part III. Commands Internal commands: alias, cd, echo, pwd, time External commands, code is in a file: grep, ls, more.
CS 497C – Introduction to UNIX Lecture 27: - The Process Chin-Chih Chang
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Process Description and Control A process is sometimes called a task, it is a program in execution.
Phones OFF Please Processes Parminder Singh Kang Home:
5 UNIX Processes. Introduction  Processes  How to list them  How to terminate them  Process priorities  Scheduling jobs  Signals.
UNIX Processes. The UNIX Process A process is an instance of a program in execution. Created by another parent process as its child. One process can be.
Operating Systems Yasir Kiani. 22-Sep Agenda for Today Review of previous lecture Process management commands: bg, fg, ^Z, jobs, ^C, kill Thread.
Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
Linux+ Guide to Linux Certification, Third Edition
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 6 System Calls OS System.
Process Control. Module 11 Process Control ♦ Introduction ► A process is a running occurrence of a program, including all variables and other conditions.
Managing processes and services. 1. How Linux handles processes 2. Managing running processes 3. Scheduling processes.
Linux+ Guide to Linux Certification, Second Edition Chapter 10 Managing Linux Processes.
RH030 Linux Computing Essentials
SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to UNIX / Linux - 8 Dr. Jerry Shiao, Silicon Valley University.
The kernel considers each program running on your system to be a process A process lives as it executes, with a lifetime that may be short or long A process.
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
Scis.regis.edu ● CS 468: Advanced UNIX Class 4 Dr. Jesús Borrego Regis University 1.
Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes.
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
1 © 2000 John Urrutia. All rights reserved. Session 5 The Bourne Shell.
CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT Processes.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 9 Working.
CSC414 “Introduction to UNIX/ Linux” Lecture 3
Agenda Managing Processes (Jobs) Command Grouping Running jobs in background (bg) Bringing jobs to foreground (fg), Background job status (jobs) Suspending.
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.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
Chapter 16 Advanced Bourne Shell Programming. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Objectives To discuss numeric data processing.
Process Relationships Chien-Chung Shen CIS/UD
OS Assignment 3.
Chapter 3: Processes.
Processes A process is a running program.
Structure of Processes
Chapter 6: CPU Scheduling
Process Models, Creation and Termination
The Linux Command Line Chapter 10
Operating Systems Lecture 6.
Operating Systems Lecture 5.
CHAPTER 8 ( , ) John Carelli, Instructor Kutztown University
Operating Systems Lecture 12.
Process & its States Lecture 5.
CHAPTER 13 Processes.
CSC 140: Introduction to IT
Process Description and Control
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Linux Shell Script Programming
Controlling Processes
Chapter 3: Processes.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix and Windows
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Processes – Part I.
Lab 6: Process Management
Lecture 6 Introduction to Process Management
Chapter 3: Process Management
Presentation transcript:

Chapter 13 Processes

Objectives To describe the concept of a process, and execution of multiple processes on a computer system with a single CPU To explain how a shell executes commands To discuss process attributes To explain the concept of foreground and background processes, including a description of a daemon To describe sequential and parallel execution of commands To discuss process and job control in UNIX; foreground and background processes, suspending processes, moving foreground processes into background and vice versa, and terminating processes To describe the UNIX process hierarchy To cover commands and primitives Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Introduction A process is a program in execution A process is created every time you run an external command and is removed after the command finishes its execution Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Running Multiple Processes Simultaneously The time a process is ‘in’ the CPU burst before it is switched ‘out’ of the CPU is called the quantum or time slice The technique used to choose the process that gets to use the CPU is called CPU scheduling Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Running Multiple Processes Simultaneously (contd.) Firstcome,First-serve(FCFS) The process that enters the system first is assigned the highest priority Assign priority value based on the amount of time a processor has used the CPU; a newly arriving process or a process that spends most of its time doing I/O operations(I/O bound processes) Round Robin (RR) A process gets to use the CPU for one quantum and then the CPU is given to another process, the next process in the queue of processes waiting to use the CPU Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Running Multiple Processes Simultaneously (contd.) Processor Scheduler The operating system code that implements the CPU scheduling algorithm Dispatcher The OS code that takes the CPU away from the current process and hands it over to the newly scheduled process Priority value=Threahold priority + Nice value +(Recent CPU usage/2) Threshold priority is an integer having a value of 40 or 60 CPU usage is the number of clock ticks for which the process has used the CPU Nice value is a positive integer with a default value of 20 Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Unix Process States A UNIX process can be in one of many states , as it moves from one state to another , eventually finishing its execution(normally or abnormally) and getting out of the system Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Unix Process States Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Execution of shell Commands A shell command can be external or internal An internal (built-in) command is one whose code is part of the shell process bg, cd,continue, echo, exec An external command is one whose code is in a file; contents of the file can be binary code or shell script grep,more ,cat, mkdir, rmdir, ls A UNIX process can create another process by using the fork system call, which creates an exact main memory map of the original process The forking processis known as the parent process The created (forked ) process is called the child process Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Execution of shell Commands (cont.) Process Creation Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Execution of shell Commands (contd.) For executing an external binary command that allows a child process to become the command to be executed exec system call can be used to allow a process to overwrite itself with the executable code for another command A shell uses the fork and exec system calls in tandem to execute an external binary command Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Execution of shell Commands (contd.) Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Execution of shell Commands (contd.) Shell script: a series of shell commands in a file Execution of a shell script is different from execution of an external binary command Execution of a shell script: The current shell creates a child shell and lets the child shell execute commands in the shell script, one by one. The child shell creates a child for every command it executes While the child shell is executing commands in the script file, the parent shell waits for the child to terminate, after which it comes out of waiting state and resumes execution Only purpose of child shell is to execute commands and eof means no more commands Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Execution of shell Commands (contd.) Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Execution of shell Commands (contd.) Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Execution of shell Commands (contd.) % ps PID TTY TIME CMD 15672 pts/0 :03 -csh % sh $ echo This is Bourne shell. This is Bourne shell. $ ksh $ echo This is Korn shell. This is Korn shell. $ ps PID TTY TIME CMD 15672 pts/0 0:03 -csh 15772 pts/0 0:00 sh 15773 pts/0 0:00 ksh $ ^D % Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Process Attributes Owner’s ID, process name, process ID(PID), process state, PID of parent process, length of time process has been running The ps command can be used to view the attributes of of processes running on the system ps [options] (System V version) Purpose Report process status Output Attributes of process running on the system Commonly used options/features: -a Display Information about the processes executing on your terminal except the session header (your login shell) -e Display information about all the processes running on the system -l Display long list(14 cols) of status report -u uidlist Display information about processes belonging to the users with UIDs in the ‘uidlist’ (UIDs separated by commas) Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Process Attributes (contd.) $ ps PID TTY TIME CMD 19440 pts/1 0:02 -ksh 18786 pts/1 0:00 ps 20668 pts/1 0:10 vi $ $ ps –a PID TTY TIME CMD 20668 pts/ 1 0:10 vi 21534 pts/1 0:00 ps $ ps -u 147 UID PID TTY TIME CMD 147 18802 pts/1 0:00 ps 147 19440 pts/1 0:02 ksh 147 20668 pts/1 0:10 vi $ ps –l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 200001 A 147 18630 19440 13 66 20 fedf 288 pts/1 0:00 ps 240001 A 147 19440 19496 1 60 20 9e93 476 pts/1 0:02 ksh 20200011 T 147 20668 19440 0 64 24 ceb9 356 pts/1 0:10 vi Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

A sample run of the top command on Solaris 2 Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

The output of pressing <h> on our system Top version 3.5beta12, Copyright © 1984 through 1996, William LeFebvre A top users display for UNIX These single-character commands are available: ^L —redraw screen q —quit h or ? —help; show this text d —change number of displays to show e —list errors generated by last “kill” or “renice” command i —toggle the displaying of idle processes I —same as ‘i’ k —kill processes; send a signal to a list of processes n or # —change number of processes to display o —specify sort order (size, res, cpu, time) r —renice a process s —change number of seconds to delay between updates u —display processes for only one user (+ selects all users) Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Process and Job control Unix is responsible for several process related activities including process creation, process termination, running processes in the foreground and background, suspending processes and switching processes from foreground to background and vice versa Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Foreground and Background Process and Related Commands command (for foreground execution) command &(for background execution) fg[%jobid] Purpose Resume execution of the process with job number ‘jobid’ in the foreground or move background processes to the foreground Commonly used values for ‘%jobid’ % or %+ Curent job %- Previous job %N Job Number N %Name Job beginning with ‘Name’ %?Name Command containing ‘Name’ Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Foreground and Background Process and Related Commands (contd.) bg[%jobid-list] Purpose: Resume execution of suspended processes/jobs with job numbers in ‘jobid- list’ in the background Commonly used values for ‘%jobid’: % or %+ Curent job %- Previous job %N Job Number N %Name Job beginning with ‘Name’ %?Name Command containing ‘Name’ $ find / -name foo -print > foo.paths 2> /dev/null & [1] 23467 $ Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Foreground and Background Process and Related Commands (contd.) jobs [option] [%jobid-list] Purpose: Display the status of the suspended and background processes specified in ‘jobid- list’; with no list, display the status of the current job Commonly used options/features: -l Also display PID of jobs Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

UNIX Daemons A daemon is a system process running in the background Used to offer various types of services to users and handle system administration tasks Print, e-mail, finger Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Sequential and Parallel Execution of Commands cmd1,;cmd2;…;cmdN Purpose: Execute the ‘cmd1’, ‘cmd2’, ‘cmd3’,…,’cmdN’ commands sequentially cmd1& cmd2&…cmdN& Purpose: Execute commands ‘cmd1’,cmd2’,…’cmdN’ in parallel as separate processes Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Sequential and Parallel Execution of Commands (contd.) Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Sequential and Parallel Execution of Commands (contd.) UNIX allows you to group commands and execute them as one process by separating commands using semicolons and enclosing them in parenthesis. This is called command grouping. (cmd1;cmd2;…cmdN) Purpose Execute commands ‘cmd1’,’cmd2’…,’cmdN’ sequentially but as one process Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Sequential and Parallel Execution of Commands (contd.) Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Sequential and Parallel Execution of Commands (contd.) Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Abnormal Termination of Commands and Processes Can terminate a foreground process by <Ctrl-C> Can terminate a background process: Use the kill command By first bringing the process into foreground by using the fg command and then pressing <Ctrl-C> Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Abnormal Termination of Commands and Processes (contd.) The primary purpose of a kill command is to is to send a signal (software interrupt) to a process A process can take one of three actions upon receiving a signal Accept the default action as determined by the UNIX kernel Ignore the signal Intercept the signal and take a user-defined action A signal caused by an event internal to a process is known as an internal signal or trap. A signal caused by an event external to a process is called an external signal Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Abnormal Termination of Commands and Processes (contd.) kill [-signal_number] proc-list Kill –l Purpose Send the signal for ‘signal_number’ to processes whose PIDs or jobIDs are specified in the ‘poc-list’;jobIDs must start with %.The command kill –l return a list of all signals and their names (on some systems, numbers are not displayed) Commonly used signal_numbers: 1 Hangup 2 Interrupt(<Ctrl-C>) 3 Quit(<Ctrl-\>) 9 Sure kill 15 Software signal (default signal number) Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Abnormal Termination of Commands and Processes (contd.) $ ps PID TTY TIME CMD 13495 pts/0 0:03 -ksh 13583 pts/0 9:11 find / -inum 23456 -print 13586 pts/0 5:03 find / -name foo -print 13587 pts/0 23:11 find / -name foobar -print 20577 pts/0 31:07 a.out 20581 pts/0 12:53 sort bigfile > bigfile.sorted $ kill 13583 [1] + Killed find / -inum 23456 -print & $ kill -2 13587 [3] + Killed find / -name foobar -print & $ kill -9 20577 [4] - Killed a.out & $ Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Abnormal Termination of Commands and Processes (contd.) nohup commands [args] Purpose: Run ‘command and ignore the hangup signal Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Process Hierarchy in UNIX The process which has no parent is called the init process and is the granddady of all the processes that are created so long as the system is up and running The init process has a PID of 1 The login process prompts you for your password and checks the validity of your login name and password The swapper and init processes exist throughout the life time of a system The getty process, which monitors a terminal line, lives for as long as the terminal is attached to the system Use the ptree command to display the process tree of the currently running processes on the system in a graphical form , showing the parent-child relationship Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Process Hierarchy in UNIX Copyright © 2005 Pearson Addison-Wesley. All rights reserved.