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.

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.
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.
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.
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.
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
Controlling Processes & Periodic Processes WeeSan Lee
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
Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes.
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.
CS 497C – Introduction to UNIX Lecture 27: - The Process Chin-Chih Chang
5 UNIX Processes. Introduction  Processes  How to list them  How to terminate them  Process priorities  Scheduling jobs  Signals.
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.
UNIX System Administration Handbook Chapter 4. Controlling Processes 3 rd Edition Evi Nemeth et al. Li Song CMSC691X Summer 2002.
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.
The process concept (section 3.1, 3.3 and demos)  Process: An entity capable of requesting and using computer resources (memory, CPU cycles, files, etc).
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
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.
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.
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.
Scis.regis.edu ● CS 468: Advanced UNIX Class 5 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,
Operating Systems Process Creation
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
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.
PROCESSES We will learn more about: ¨ Multi-user processing and multi −tasking ¨ Multi-user processing and multi −tasking ¨ Process types ¨ Process types.
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.
Unix System Administration Controlling Processes Chapter 5.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
Comp 145 – Introduction to UNIX $200 $400 $600 $800 $1000 $200 $400 $600 $800 $1000 $200 $400 $600 $800 $1000 $200 $400 $600 $800 $1000 UNIX Processes.
Processes Todd Kelley CST8207 – Todd Kelley1.
Foreground and background processes
Chapter 13 Processes.
...looking a bit closer under the hood
Process Management Process Concept Why only the global variables?
Hands On UNIX AfNOG 2010 Kigali, Rwanda
Unix Process Management
Hands On UNIX AfNOG X Cairo, Egypt
CHAPTER 8 ( , ) John Carelli, Instructor Kutztown University
CHAPTER 13 Processes.
CSC 140: Introduction to IT
Processes – Part I.
Lab 6: Process Management
Lecture 6 Introduction to Process Management
Presentation transcript:

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 parent of multiple children. The shell is the parent of the commands you run. The shell’s parent is the init process.

PID – The Process ID When born, logged in the Process Table with unique number Used to track and kill a process Shell’s PID is stored in variable $$ To see or show value of $$ use echo $$ PPID – The Process ID of the Parent Can be used to kill a child process Two Important Process Attributes

Other Process Attributes Inherited from Parent Real UID and GID Effective UID and GID Current directory File descriptors umask value Environment variables

$ ps Display a simple listing of your processes PID TT STAT TIME COMMAND p3 S 0: ksh (ksh) p3 R+ 0:00.00 ps $ ps –a Display all the users’ processes $ ps –e Display all processes including system processes $ ps –f Display a full listing of your processes $ ps –l Display a long detailed listing of processes 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 Displaying Process Status with the ps Command

Daemons in UNIX Daemons are system processes that lack terminal control. Examples: lpsched mail, mailx cron Cannot read from terminal nor write to terminal ps –e shows all daemons running.

Exporting and Environment Variables A local variable is not visible in child processes: $ x=5 ; sh Create a child process $ echo $x No value in child! An exported variable is visible in all child processes: $ x=5 ; export x x is now environmental $ sh ; echo $x Create a child process 5 Changes made in child are not available in parent: $ x=7 Value set in child $ exit Child dies; back to parent $ echo $x 5 Original value in parent

The UNIX Process Cycle A parent process forks a child by replicating its own process image. The child process execs (overwrites) this image with that of another program. While the child is running, parent may wait for child to complete execution (foreground execution). continue with its other tasks (background execution). The process terminates and parent picks up exit status of child. Kernel removes entry for dead child from process table.

When the Child Dies Before the Parent When child dies, it leaves behind an exit status in process table. Parent process may pick up exit status; remove child entry in process table; child is now completely dead OR may not wait; child entry not removed from process table; child in zombie state. Zombies can’t be killed but are harmless (they take up space); shown as in ps output.

When the Parent Dies Before the Child Child becomes an orphan. Child adopted by init process. PPID of child changes to 1 (init process). Orphan processes continue to operate until killed or ends normally. When child dies, init picks up the exit status.

Signals Used by kernel to communicate with processes (e.g., notification of occurrence of an event, e.g. a keyboard press). Process may perform the default action OR ignore the signal OR catch the signal and invoke a signal-handling function (trap). Some important signals SIGINT (interrupt key)SIGQUIT (quit and core dump) SIGSTOP (suspend key)SIGKILL (a sure kill, but not a keyboard event)

No keyboard event generates a kill. Kill signals cannot be trapped. You must kill using this command. kill Example: $ kill (kills process ) Results are not reversible. Terminating Processes with the kill Command

Running a Job in the Background Job is run in background with &. Frees keyboard screen for other uses. Example: sort empl.lst > junk2 & If you logout before it’s finished, the job may be terminated. Using nohup (no hang up) and &, the job will run even after logging out. Example: nohup sort empl.lst > junk2 & Use nohup with every command in a pipeline. Example: nohup grep book | nohup sort > sortedfile &

Job Control Job control supported by most shells but not Bourne. Job accessed by job number usually shown in brackets e.g., [1]. Apart from background execution, job control allows suspending a job ([Ctrl-z]). bringing a background job to foreground: fg %1 moving a suspended job to foreground or background: bg %find The jobs command lists all running/ suspended jobs. The kill command can also take a job id e.g., kill %3

Scheduling a Process to Run Periodically cron Kernel started daemon (UNIX’s chronograph) Wakes up each minute to execute what is in crontabs file crontab Takes as input a user edited file Used to insert jobs in crontabs file 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 (adds content of user’s file to crontabs )

crontab File Format minutes hours days of month months days of week command Minutes: 00 to 59, can be expressed as a range e.g., 00-15, or 0,15,30,45 Hours : 0 to 23 Day in month: 0 to max # days in month Month: 1 to 12 Days of week: 0 to 6, where 0=Sunday Use asterisk (*) to indicate all Use comma (,) to indicate a set of values Use hyphen (-) to indicate a range of values

crontabs File Format Examples ,20,30 * 1,3 find / -newer.last_time - print >bkup Execute the find command either 3 days of the month or Monday and Wednesday of each month * * 4 find / -newer.last_time -print > bkup Execute the find command every Thursday at 5:55 pm. 0,30 * * * * find / -newer.last_time -print >bkup Execute the find command every 30 minutes on the half hour.

at hh:mm or at Examples: at 15:08 at noon + 1 year at> flush.sh >rep.lst at> cleanup.sh > clean.lst ctl-d ctl-d batch - put in batch queue and run the job later runs when resource utilization levels are low. have lower priority than user foreground jobs. Example: batch < checkusers.sh System may limit use of these commands. Scheduling a Process to Run Later