U NIX C OMP -145 L ECTURE 5: UNIX P ROCESSES T EXT : S. D AS, “Y OUR U NIX : T HE ULTIMATE G UIDE ”, 2 ND E DITION, M C G RAW H ILL, 2006 10/22/2009 rwjBROOKDALE.

Slides:



Advertisements
Similar presentations
Job and Process Management
Advertisements

June 1, 1999Foreground/Background Processing1 Introduction to UNIX H. Foreground/Background Processing.
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
U NIX C OMP -145 L ECTURE 1: C ONCEPTS OF THE UNIX O PERATING S YSTEM S OURCE : S. D AS, “Y OUR U NIX : T HE ULTIMATE G UIDE ”, 2 ND E DITION, M C G RAW.
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.
A Practical Guide to Fedora and Red Hat Enterprise Linux Unit 4: More Command Line Interface (CLI) Chapter 7: The Linux Shell By Fred R. McClurg Linux.
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.
CSCI 330 T HE UNIX S YSTEM Shell Job Control. T ODAY ’ S CLASS Unix is multi-user, multi-process OS Shell features to control jobs Unix utilities to manage.
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.
Process Management We studied process management in chapter 4 – Here, we examine managing processes from a user’s and system administrator’s perspective.
Shells and Processes Bryce Boe 2012/08/08 CS32, Summer 2012 B.
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
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.
CS 497C – Introduction to UNIX Lecture 27: - The Process Chin-Chih Chang
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE1 Unix Comp-145 C HAPTER 2.
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.
Server Design Discuss Design issues for Servers Review Server Creation in Linux.
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)
Processes Objectives –to become familiar with Unix processes Contents –processes & daemons –Nice levels –User limits –System resources –signals –batch.
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.
U NIX C OMP -145 L ECTURE 6: C USTOMIZING THE S HELL E NVIRONMENT T EXT : S. D AS, “Y OUR U NIX : T HE ULTIMATE G UIDE ”, 2 ND E DITION, M C G RAW H ILL,
Linux+ Guide to Linux Certification, Third Edition
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.
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
Hands On UNIX II Dorcas Muthoni. Processes A running instance of a program is called a "process" Identified by a numeric process id (pid)‏  unique while.
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.
Unix Comp-145 L ECTURE 9: I NTRODUCTION TO S YSTEM A DMINISTRATION S OURCE : S. D AS, “Y OUR U NIX : T HE ULTIMATE G UIDE ”, 2 ND E DITION, M C G RAW H.
Operating Systems Process Creation
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
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.
Chapter 4 The UNIX Shells (Bourne shell, Korn shell, C shell)‏ Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice.
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.
UNIX-21 WEEK 2 4/5/2005. UNIX-22 TOPICS Functions (contd.) pushd, popd, dirs Debugging Shell scripts Scheduling Unix jobs Job Management.
Processes Todd Kelley CST8207 – Todd Kelley1.
Chapter 13 Processes.
...looking a bit closer under the hood
Chapter 11 – Processes and Services
Hands On UNIX AfNOG 2010 Kigali, Rwanda
Shell Script Assignment 1.
Hands On UNIX AfNOG X Cairo, Egypt
The Linux Command Line Chapter 10
CHAPTER 8 ( , ) John Carelli, Instructor Kutztown University
CHAPTER 13 Processes.
CSC 140: Introduction to IT
Linux Shell Script Programming
Lab 6: Process Management
Lecture 6 Introduction to Process Management
LPI Linux Certification
Presentation transcript:

U NIX C OMP -145 L ECTURE 5: UNIX P ROCESSES T EXT : S. D AS, “Y OUR U NIX : T HE ULTIMATE G UIDE ”, 2 ND E DITION, M C G RAW H ILL, /22/2009 rwjBROOKDALE COMMUNITY COLLEGE1

2 U NIX O PERATING S YSTEM T HE UNIX PROCESS STRUCTURE P ROCESS I NITIALIZATION S EQUENCE P ROCESS C ONTROL C OMMANDS R UNNING S HELL S CRIPTS IN B ACKGROUND P ROCESS S IGNALING AND E XIT S TRUCTURE E XECUTE &T ERMINATE P ROCESSES S CHEDULE A P ROCESS TO R UN A UTOMATICALLY 10/22/2009 rwj

BROOKDALE COMMUNITY COLLEGE3 T HE P ROCESS A N INSTANCE OF A PROGRAM IN EXECUTION. I DENTIFIED BY A UNIQUE PID (P ROCESS - ID ). C REATED BY ANOTHER PROCESS AS ITS CHILD O NE PROCESS CAN BE PARENT OF MULTIPLE CHILDREN C AN BE KILLED OR STOPPED BY SENDING IT A SIGNAL 10/22/2009 rwj

T HE P ROCESS C YCLE P ARENT FORKS A CHILD BY 1 ST REPLICATING ITS OWN PROCESS IMAGE AND LOGGING THE CHILD IN THE PROCESS TABLE. C HILD EXECUTES ( OVERWRITES ) THIS IMAGE WITH THAT OF ANOTHER PROGRAM. W HILE CHILD IS RUNNING, PARENT MAY  W AIT FOR CHILD TO COMPLETE EXECUTION (I F A CHILD EXECUTING IN FOREGROUND )  C ONTINUE WITH ITS OTHER TASKS (I F A CHILD EXECUTING IN FOREGROUND ) P ROCESS TERMINATES AND PARENT PICKS UP EXIT STATUS OF CHILD.  Until Parent picks up exit status of child, process called a ZOMBIE, because process not removed K ERNEL REMOVES ENTRY FOR DEAD CHILD FROM PROCESS TABLE. 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE4

10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE5 T HE P ROCESS C YCLE (contd) I F P ARENT PROCESS DIES BEFORE A CHILD PROCESS  C HILD PROCESS CALLED AN ORPHAN  P ROCESS init BECOMES PARENT OF CHILD, AS IT IS FOR MOST DAEMONS  O RPHAN PROCESSES CONTINUE TO OPERATE UNTIL ITS KILLED OR ENDS NORMALLY.

10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE6 M ORE ON THE P ROCESS B UILT IN S HELL COMMANDS DO NOT FORK SEPARATE A PROCESS  F OR EXAMPLE : cd or pwd S HELL SCRIPTS USE SUB - SHELLS TO RUN COMMANDS IN SCRIPT SIGNALS: U SED BY K ERNEL TO COMMUNICATE WITH A PROCESS  kill -s, OR  GENERATED THROUGH YOUR keyboard

10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE7 P ROCESS A TTRIBUTES I NHERITED BY C HILD Real User ID (UID) and Group (GID) Effective UID and GID Current directory File descriptors umask value Environment variables

PID  Process ID – referred to as “pid”  When born, logged in Process Table with unique number  Used to track and kill a process  Stored in variable $$  To see or show value of $$ use echo $$ PPID  Parent PID, referred to as “p-pid”  Can be used to kill a child process but only be used if 1 child spawned $ ps PID TT STAT TIME COMMAND p3 S 0: ksh (ksh) p3 R+ 0:00.00 ps $ P ROCESS A TTRIBUTES N OT I NHERITED BY C HILD 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE8

10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE9 P ROCESS C ONTROL C OMMANDS ps ( PROGRAM STATUS ) kill ( TERMINATE PROCESS )

D ISPLAY ENVIRONMENT  S PECIFIES A LIST OF DIRECTORIES TO SEARCH. $ ps –e PID TT STAT TIME COMMAND p3 S 0: ksh (ksh) p3 R+ 0:00.00 ps –e P ROGRAM S TATUS ( ps ) BROOKDALE COMMUNITY COLLEGE1010/22/2009 rwj

D ISPLAY COMMAND - LINE AND ENVIRONMENT INFO ABOUT SWAPPED OUT PROCESSES. UID OF USE MUST BE 0. $ ps –f PID TT STAT TIME COMMAND p3 S 0: ksh (ksh) p3 R+ 0:00.00 ps –f 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE11 P ROGRAM S TATUS ( ps ) (contd)

D ISPLAY DETAILED PROCESS LISTING $ ps –l UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND pause S p3 0: ksh (ksh) R+ p3 0:00.00 ps –l 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE12 P ROGRAM S TATUS ( ps ) (contd)

10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE13 R UNNING JOBS IN THE B ACKGROUND A PPEND & ( AMPERSAND ) TO THE END OF A SHELL OR COMMAND  S HELL OPERATOR TO RUN IN BACKGROUND  F REES KEYBOARD AND SCREEN FOR USE. $ sort empl.lst > junk2 &

10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE14 R UNNING JOBS IN THE B ACKGROUND (contd) P REPEND nohup ( NO HANG UP ) IN FRONT OF A SHELL OR COMMAND  S HELL OPERATOR TO NOT TERMINATE THE COMMAND RUNNING IN BACKGROUND EVEN IF THE SESSION ENDS $ nohup sort empl.lst > junk2 &  U NIKE &, USE nohup WITH EACH COMMAND IN A PIPELINE, E. G. $ nohup grep directory | nohup sort > empl_directors_sorted&

10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE15 P ROCESS S IGNALING AND E XIT S TRUCTURE J OB CONTROL USES AS IT RELATES TO PGID  M OVE JOBS BETWEEN FOREGROUND AND BACKGROUND  C OMMANDS fg bg suspend ( OUTPUT TO TERMINAL ) jobs ( LISTS CURRENTLY ACTIVE JOBS ) kill ( TERMINATES JOBS ) ctl-z ( SUSPENDS CURRENT FOREGROUND JOB )

10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE16 E XECUTE & T ERMINATE P ROCESSES J OB CONTROL COMMANDS  S TART A COMMAND IN THE BACKGROUND $ find / -name a.out –print > files_to_remove 2>dev/null & [1] 1287 $ ls -lR / > system_list 2>dev/null & [2] 1288 $ du -s /usrs1/* > disk_usage & [3] 1289 S TOP OUTPUT TO THE TERMINAL + SUSPEND JOB  S USPENDS JOB WHEN TRIES TO WRITE TO TERMINAL $ stty tostop

10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE17 E XECUTE & T ERMINATE P ROCESSES (contd) U SE OF JOB CONTROL FUNCTIONS  U SING JOB NUMBER MOVE TO FOREGROUND $ fg %1  S USPENDS ONLY A FOREGROUND JOB $ [ ctl-z ]  U SING JOB NUMBER RETURN JOB 1 TO BACKGROUND $ bg %1  W HEN JOB ENDS NORMALLY GET $ [2]- Exit 1 ls -lR / > system_list 2>dev/null  W HEN JOB NEEDS TO BE KILLED MANUALLY USE $ kill %2 [1] + Terminated ls -lR / > system_list 2>dev/null

10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE18 kill or  Pid SPECIFIES THE PROCESS THAT THE OS IS TO KILL  T HE RESULT IS NOT REVERSIBLE. $ kill $ kill %1 T ERMINATE P ROCESSES

10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE19 D AEMON IN UNIX S CRIPTS THAT LACK TERMINAL CONTROL $ lpsched $ mail, mailx, cron ps –e SHOWS cron DAEMON RUNNING. P ROGRAMS INVOKED BY LAUNCHING A SHELL OR SUB - SHELL  S HELL S CRIPTS  S UB - SHELL READS & EXECUTES EACH STATEMENT IN SCRIPT

10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE20 S CHEDULE A P ROCESS TO R UN A UTOMATICALLY cron vs crontab  cron K ERNEL STARTED DAEMON S TARTED EACH MINUTE TO EXECUTE WHAT IS IN A USER ’ S crontab FILE  crontab T AKES AS INPUT A USER EDITED FILE U SED TO INSERT JOBS TO BE EXECUTED BY cron DAEMON crontab –r ( REMOVES CONTENT FROM A USER ’ S crontab FILE ) crontab –l ( LISTS CONTENT OF USER ’ S crontab FILE ) crontab ( LISTS CONTENT OF USER ’ S crontab FILE )

10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE21 S CHEDULE A P ROCESS TO R UN A UTOMATICALLY (contd) CRONTAB file’s entry syntax: minutes, hours, days of month, month, days of week, command o M INUTES : 00 TO 59, CAN BE EXPRESSED AS A RANGE E. G., 00-15, or 0,15,30,45 o H OURS : 0 TO 23, # of hours o D AY IN MONTH : 0 TO MAX # DAYS IN MONTH o M ONTH : 1 TO 12 o D AYS OF WEEK : 0 TO 6, WHERE 0=S UNDAY o U SE ASTERISK (*) TO INDICATE ALL o U SE COMMA (,) TO INDICATE A SET OF VALUES o U SE HYPHEN (-) TO INDICATE A RANGE OF VALUES

10/08/2009 rwjBROOKDALE COMMUNITY COLLEGE22 S CHEDULE A P ROCESS TO R UN A UTOMATICALLY (contd) E XAMPLES OF ENTRIES IN A crontab FILE minutes, hours, days of month, month, days of week, command ,20,30 * 1,3 find / -newer.last_time -print >backuplist ( E XECUTE THE COMMAND EITHER 3 DAYS OF THE MONTH OR M ONDAY AND W EDNESDAY OF EACH MONTH ) * * 4 find / -newer.last_time -print >backuplist ( E XECUTE THE COMMAND EVERY T HURSDAY AT 5:55 PM ) 0,30 * * * * find / -newer.last_time -print >backuplist ( E XECUTE THE COMMAND EVERY 3 O MINUTES ON THE HALF HOUR )

10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE23 U TILITY FOR ONE TIME EXECUTION at - SAME DATE, FORMAT hhmm OR hh:mm at –t - SCHEDULED, FORMAT [[CC]YY]MMDDhhmm[.SS] $ at 15:08 at> empawk2.sh > rep.lst at –l- LISTS ITEMS IN “ at” QUEUE at -r - re MOVES ITEM FROM “ at” QUEUE at –m E XECUTE AS A BATCH JOB IN “at” QUEUE  B ATCH JOBS ARE RUN WHEN RESOURCE UTILIZATION LEVELS ARE LOW,  H AVE LOWER PRIORITY THAN USER FOREGROUND JOBS  S UBMITS JOB TO RUN IN BATCH QUEUE batch < empawk22.sh S CHEDULE A P ROCESS TO R UN A UTOMATICALLY (contd)

10/08/2009 rwjBROOKDALE COMMUNITY COLLEGE24 S UMMARY P ROCESS C YCLE  W HAT PARENT OR CHILD CAN DO WHILE OTHER IS RUNNING P ROGRAM STATUS COMMAND R UNNING A PROCESS  B ACKGROUND  F OREGROUND  T ERMINATE A PROCESSES CRON AND RELATED COMMANDS