CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT Processes.

Slides:



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

UNIX Process Processes Commands that deal with processes
Chapter 5 Controlling Processes Xiaoli Jiao 6/8/99.
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.
Processes and Job Control. Foreground and Background (1)  Unix is a multi-tasking operating system –some of these tasks are being done by other users.
Job Control Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Chapter 13 Processes. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Objectives To describe the concept of a process, and execution of.
Introduction to Unix – CS 21 Lecture 10. Lecture Overview Midterm questions Jobs and processes description The foreground and background Controlling jobs.
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.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Operating Systems Yasir Kiani. 20-Sep Agenda for Today Review of previous lecture Use of FIFOs in a program Example code Process management commands.
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
Linux+ Guide to Linux Certification, Second Edition
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
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.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
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.
UNIX System Administration Handbook Chapter 4. Controlling Processes 3 rd Edition Evi Nemeth et al. Li Song CMSC691X Summer 2002.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process System Process and init.
UNIX and Shell Programming (06CS36)
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
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
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.
Lecture – Performance Performance management on UNIX.
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.
Processes Dr. Yingwu Zhu. Process Concept Process – a program in execution – What is not a process? -- program on a disk - a process is an active object,
CIT 140: Introduction to ITSlide #1 CIT 140: Introduction to IT Shell Programming.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
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.
CS 390 Unix Programming Environment
Processes 2 Introduction to Operating Systems: Module 4.
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.
PROCESSES We will learn more about: ¨ Multi-user processing and multi −tasking ¨ Multi-user processing and multi −tasking ¨ Process types ¨ Process types.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
An Introduction to processes R Bigelow. A Unix Process A process in Unix is simple a program The Unix system is made up of a group of processes all interacting.
Processes Todd Kelley CST8207 – Todd Kelley1.
Chapter 13 Processes.
The UNIX Shell Learning Objectives:
Processes A process is a running program.
Shell Script Assignment 1.
CHAPTER 8 ( , ) John Carelli, Instructor Kutztown University
CHAPTER 13 Processes.
CSC 140: Introduction to IT
Linux Shell Script Programming
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes – Part I.
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
Lecture 6 Introduction to Process Management
Presentation transcript:

CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT Processes

CIT 140: Introduction to ITSlide #2 Topics 1.What is a process? 2.Process states and multitasking 3.How does the shell execute processes? 4.Foreground and background processes 5.Job control 6.Process tree 7.Process commands

CIT 140: Introduction to ITSlide #3 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.

CIT 140: Introduction to ITSlide #4 Multitasking Only one process is using a CPU at a time. A process uses the CPU until: 1.It makes an I/O request, or 2.It reaches the end of its time slice, or 3.It is terminated. The technique used to choose the process that gets to use the CPU next is called Process scheduling.

CIT 140: Introduction to ITSlide #5 Process State As a process executes, it changes state new: The process is being created. running: Instructions are being executed. waiting: The process is waiting for some event to occur. ready: The process is waiting to be assigned to a CPU. terminated: The process has finished execution. zombie: Process has been terminated and is waiting for its resources to be recovered.

CIT 140: Introduction to ITSlide #6 Process States A UNIX process can be in one of many states, typically ready, running, or waiting.

CIT 140: Introduction to ITSlide #7 Process Scheduling First come, First serve(FCFS) –Process that enters system first is assigned highest priority. Priority Scheduling –Assign priorities based on accumulated CPU time. –New and I/O bound processes have highest priorities. Round Robin (RR) –A process gets to use the CPU for one time slice, then the CPU is given to another process, the next process in the queue of processes waiting to use the CPU.

CIT 140: Introduction to ITSlide #8 Process Scheduling Modern UNIX scheduler uses mixture of strategies. –Priority values constantly recalculcated. –Smallest priority numbers have highest priority. Priority value = Threshold priority + Nice value + (Recent CPU usage/2) –Threshold priority is an integer from 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 of 20.

CIT 140: Introduction to ITSlide #9 Execution of shell Commands A shell command can be external or internal. Internal (built-in) command: is part of the shell: ex: bg, cd, continue, echo, exec External command: separate program or script ex: grep, more, cat, mkdir, rmdir, ls

CIT 140: Introduction to ITSlide #10 Execution of shell Commands A UNIX process is created by the fork() system call, which creates an exact copy of the original process. The forking processis known as the parent process. The created (forked) process is called the child process.

CIT 140: Introduction to ITSlide #11 Execution of shell Commands To execute an external command, the exec() system call is used after fork. exec() replaces the current process in memory with the specified file and begins running it.

CIT 140: Introduction to ITSlide #12 Execution of shell Commands

CIT 140: Introduction to ITSlide #13 Execution of Shell Scripts Shell script: a series of shell commands in a file Execution different from binary programs. –Current shell creates a child shell and lets the child shell execute commands in the shell script, one by one. –Child shell creates a child process 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.

CIT 140: Introduction to ITSlide #14 Execution of shell Commands

CIT 140: Introduction to ITSlide #15 Execution of shell Commands % ps PIDTTY TIME CMD 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 pts/0 0:03 -csh pts/0 0:00 sh pts/0 0:00 ksh $ ^D %

CIT 140: Introduction to ITSlide #16 Execution of shell Commands (contd.)

CIT 140: Introduction to ITSlide #17 Process Attributes Processes have a variety of attributes: 1.User owner 2.Group owner 3.Process name 4.Process ID (PID) 5.Parent process ID (PPID) 6.Process state 7.Length of time running 8.Amount of memory used

CIT 140: Introduction to ITSlide #18 Process Status ps [options] (System V version) PurposeReport process status OutputAttributes of process running on the system Commonly used options/features: -aDisplay Information about the processes executing on your terminal except the session header (your login shell) -eDisplay information about all the processes running on the system -fDisplay full list (8 columns) of status report. -lDisplay long list (14 columns) of status report. -u uidlistDisplay information about processes belonging to the users with UIDs in the ‘uidlist’ (UIDs separated by commas)

CIT 140: Introduction to ITSlide #19 Examples of ps > ps PID TTY TIME CMD pts/13 0:00 bash pts/13 0:00 ps > ps -f UID PID PPID C STIME TTY TIME CMD waldenj :51:55 pts/13 0:00 -bash waldenj :55:06 pts/13 0:00 /usr/bin/ps -f > ps -l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 8 S ? 331 ? pts/13 0:00 bash 8 O ? 123 pts/13 0:00 ps > ps -ef|head UID PID PPID C STIME TTY TIME CMD root Jun 16 ? 0:01 sched root Jun 16 ? 1:39 /etc/init - root Jun 16 ? 0:01 pageout root Jun 16 ? 970:56 fsflush root Jun 16 ? 0:00 /usr/lib/saf/sac -t 300 root Jun 16 ? 0:00 /usr/lib/snmp/snmpdx -y -c /etc/snmp/conf root Jun 16 ? 0:05 /usr/sbin/vold root Jun 16 ? 0:00 /usr/lib/sysevent/syseventd root Jun 16 ? 0:01 /usr/lib/picl/picld

CIT 140: Introduction to ITSlide #20 Top Top shows process activity in real time. By default, top shows –Summary of CPU/memory usage. –Highest 15 CPU using processes. –Updated every 5 seconds. Top commands h Help mShow top processes by memory usage qQuit

CIT 140: Introduction to ITSlide #21 Example top Output load averages: 0.12, 0.13, 0.14 zappa 14:57: processes: 99 sleeping, 2 stopped, 1 on cpu CPU states: 83.3% idle, 0.6% user, 16.1% kernel, 0.0% iowait, 0.0% swap Memory: 512M real, 253M free, 238M swap in use, 1.1G swap free PID USERNAME THR PR NCE SIZE RES STATE TIME FLTS CPU COMMAND waldenj K 1152K cpu00 0: % top mysql M 5272K sleep 133: % mysqld waldenj K 2056K sleep 0: % bash 232 root K 1504K sleep 7: % sendmail 349 root K 1728K sleep 47: % mibiisa 191 root K 1616K sleep 9: % syslogd 343 root M 4784K sleep 7: % Xsun 361 root K 2896K sleep 2: % dtgreet 209 root K 2400K sleep 1: % nscd 1 root K 248K sleep 1: % init 5069 nobody M 14.0M sleep 0: % httpd 5675 glasnova K 560K sleep 0: % generate 5683 glasnova K 560K sleep 0: % generate 348 root K 912K sleep 0: % fbconsole nobody M 12.1M sleep 0: % httpd

CIT 140: Introduction to ITSlide #22 Process and Job control Shell manages your processes for you: –Process creation –Process termination –Suspending processes –Running foreground processes. –Running background processes. –Switching processes to foreground/background.

CIT 140: Introduction to ITSlide #23 Foreground and Background Default is to run processes in foreground > find / -name foo –print >foo.out 2>/dev/null > bzip2 foo.out User must wait for foreground process to finish to have shell prompt. Run processes in background with & > find / -name foo –print >foo.out 2>/dev/null & > bzip2 foo.out &

CIT 140: Introduction to ITSlide #24 Example of Background Processes > find / -name foo 2>/dev/null & [1] > bzip2 bash.man & [2] > ps PID TTY TIME CMD pts/13 0:00 bash pts/13 0:03 find pts/13 0:00 ps > [2]+ Done bzip2 bash.man

CIT 140: Introduction to ITSlide #25 Suspending a Process What if you forgot to background a process? –Suspend the process with –Use fg or bg to unsuspend process. Use stop to suspend background processes. –If you don’t have a stop command, use alias stop=“kill –STOP” –Example

CIT 140: Introduction to ITSlide #26 Managing Background Processes: fg 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 %NJob Number N %NameJob beginning with ‘Name’ %?NameCommand containing ‘Name’

CIT 140: Introduction to ITSlide #27 Managing Background Processes: bg 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’

CIT 140: Introduction to ITSlide #28 Managing Background Processes: jobs 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: -lAlso display PID of jobs > find / -name foo 2>/dev/null & [1] > bzip2 bigFile & [2] > jobs [1]- Running find / -name foo 2>/dev/null & [2]+ Running bzip2 bigFile & > fg %2 >

CIT 140: Introduction to ITSlide #29 Which job is the current job? The current job is either 1)The most recently stopped job, or 2)If no stopped jobs exist, the most recent background job. The following fg will return you to vim, not sleep. > vim smallFile Ctrl-z [2]+ Stopped vim smallFile > sleep & [3] > fg

CIT 140: Introduction to ITSlide #30 UNIX Daemons A daemon is a system process running in the background. Most system services are daemons: Printing Ssh Web

CIT 140: Introduction to ITSlide #31 Sequential and Parallel Execution cmd1; cmd2; … ; cmdN Purpose: Execute the ‘cmd1’, ‘cmd2’, ‘cmd3’,…,’cmdN’ commands in sequence. cmd1 & cmd2 & … & cmdN & Purpose: Execute commands ‘cmd1’,cmd2’,…’cmdN’ in parallel as separate processes.

CIT 140: Introduction to ITSlide #32 Sequential and Parallel Execution > date; bzip2 -v bigFile; date Sat Nov 5 15:28:19 EST 2005 bigFile: :1, bits/byte, 91.19% saved, in, out. Sat Nov 5 15:28:28 EST 2005 > date & bzip2 -v bigFile & echo Hello, World & uname -a & date [1] Sat Nov 5 15:30:29 EST 2005 [2] Hello, World bigFile: [3] SunOS zappa 5.9 Generic_ sun4u sparc SUNW,Ultra-250 [4] Sat Nov 5 15:30:29 EST 2005 [1] Done date [3] Done echo Hello, World [4] Done uname -a > :1, bits/byte, 91.19% saved, in, out. [2]+ Done bzip2 -v bigFile

CIT 140: Introduction to ITSlide #33 Combining Sequential and Parallel

CIT 140: Introduction to ITSlide #34 Subshells Shell scripts run in a subshell. You can start a subshell without a script –Group commands using ()’s –Use ; to separate sequence of commands. Advantages of subshells –Redirect I/O of a group of commands at once. –Put group of commands in background at once. –Manage group of commands as a single background process.

CIT 140: Introduction to ITSlide #35 Subshells > (date; ps -ef; ls -l) | bzip2 -c >subshell.bz2 > bzcat subshell.bz2 |head Sat Nov 5 15:33:15 EST 2005 UID PID PPID C STIME TTY TIME CMD root Jun 16 ? 0:01 sched root Jun 16 ? 1:39 /etc/init - root Jun 16 ? 0:01 pageout root Jun 16 ? 971:09 fsflush root Jun 16 ? 0:00 /usr/lib/saf/sac -t 300 root Jun 16 ? 0:00 /usr/lib/snmp/snmpdx -y -c /etc/snmp/conf root Jun 16 ? 0:05 /usr/sbin/vold root Jun 16 ? 0:00 /usr/lib/sysevent/syseventd

CIT 140: Introduction to ITSlide #36 Subshells > (date; bzip2 -v bigFile; date) >bzPerf.txt 2>&1 & [1] > ps PID TTY TIME CMD pts/13 0:00 bash pts/13 0:00 bash pts/13 0:00 ps pts/13 0:02 bzip2 > fg ( date; bzip2 -v bigFile; date ) >bzPerf.txt 2>&1 ^Z [1]+ Stopped ( date; bzip2 -v bigFile; date ) >bzPerf.txt 2>&1 > bg [1]+ ( date; bzip2 -v bigFile; date ) >bzPerf.txt 2>&1 & > who newell pts/2 Nov 1 13:09 ( ) walden pts/13 Nov 5 14:51 ( ) [1]+ Done ( date; bzip2 -v bigFile; date ) >bzPerf.txt 2>&1

CIT 140: Introduction to ITSlide #37 Terminating a Process Can terminate a foreground process by Can terminate a background process: 1)Find the PID with ps, then use kill PID. 2)Bring process into foreground with fg, then use

CIT 140: Introduction to ITSlide #38 Terminating a Process > find / -name foo 2>/dev/null >foo.txt & [4] > sort bigFile | bzip2 -c >sortFile.bz2 & [5] > jobs [2]+ Stopped vim smallFile [3] Running sleep & [4] Running find / -name foo 2>/dev/null >foo.txt & [5]- Running sort bigFile | bzip2 -c >sortFile.bz2 & > kill %5 [5]- Terminated sort bigFile | bzip2 -c >sortFile.bz2 > ps PID TT S TIME COMMAND pts/4 S 0:00 -bash pts/4 T 0:00 vim smallFile pts/4 S 0:00 sleep pts/4 R 0:05 find / -name foo > kill > jobs [2]+ Stopped vim smallFile [3] Running sleep & [4]- Terminated find / -name foo 2>/dev/null >foo.txt > ps PID TT S TIME COMMAND pts/4 S 0:00 -bash pts/4 T 0:00 vim smallFile pts/4 S 0:00 sleep 10000

CIT 140: Introduction to ITSlide #39 Job Numbers vs PIDs PIDs –Every process has a PID. –PIDs are global (shared by every user.) Job Numbers –Every job has a job number. –Jobs may contain multiple processes. –Job numbers are local (every user has own %1...)

CIT 140: Introduction to ITSlide #40 Changing Process Priorities > nice -10 bzip2 biggerFile & [4] > /usr/bin/ps -l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 8 R ? 1054 pts/4 0:05 bzip2 8 O ? 123 pts/4 0:00 ps 8 T ? 1115 pts/4 0:00 vim 8 S ? 334 ? pts/4 0:01 bash > bzip2 biggerFile & [4] > renice > /usr/bin/ps -l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 8 O ? 123 pts/4 0:00 ps 8 T ? 1115 pts/4 0:00 vim 8 S ? 334 ? pts/4 0:01 bash 8 R ? 1054 pts/4 0:24 bzip2 > renice renice: 28643: Cannot lower nice value.

CIT 140: Introduction to ITSlide #41 UNIX Process Hierarchy 1.System starts init process on boot. –Init is PID 1. 2.Init starts system processes –System daemons. –Graphical login: xdm, kdm, gdm –Text login: getty -> login –Network login: sshd 3.Login runs –User shell

CIT 140: Introduction to ITSlide #42 Process Hierarchy in UNIX