5 UNIX Processes. Introduction  Processes  How to list them  How to terminate them  Process priorities  Scheduling jobs  Signals.

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.
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.
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
1 Processes Professor Jennifer Rexford
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.
Review: Operating System Manages all system resources ALU Memory I/O Files Objectives: Security Efficiency Convenience.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
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
Phones OFF Please Processes Parminder Singh Kang Home:
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.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Introduction to Processes CS Intoduction to Operating Systems.
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).
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
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.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
SUSE Linux Enterprise Server Administration (Course 3037) Chapter 6 Manage Linux Processes and Services.
Va-scanCopyright 2002, Marchany Unit 7 – Solaris Process Control Randy Marchany VA Tech Computing Center.
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.
Welcome to CS323 Operating System lab 1 TA: Nouf Al-Harbi NoufNaief.net.
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.
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.
PTA Linux Series Copyright Professional Training Academy, CSIS, University of Limerick, 2006 © Workshop VI Scheduling & Process Management Professional.
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.
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.
ULI101 Week 05. Week Overview ● File system links ● Hard and symbolic links ● Process management ● Storage quota information (quota) ● Printing.
Process Manipulation. Process Manipulation in UNIX Basic process manipulation: creation, program loading, exiting, … fork(), exec(), wait(), exit() Process.
...looking a bit closer under the hood
Chapter 11 – Processes and Services
Hands On UNIX AfNOG 2010 Kigali, Rwanda
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
Process Description and Control
Controlling Processes
Processes – Part I.
Lab 6: Process Management
Lecture 6 Introduction to Process Management
Presentation transcript:

5 UNIX Processes

Introduction  Processes  How to list them  How to terminate them  Process priorities  Scheduling jobs  Signals

Processes  Every time you run a command under UNIX it creates a process  A process is an instance of a running program  A program and process are different things. wc is a program; each time you run the program wc, that creates a new process.  A process runs until it has finished or is killed

Processes (2)  Every process has a number assigned to it called a process–ID or PID.  All the processes running on a UNIX machine are scheduled a certain amount of time on the CPU. The more that are running, the longer it will take for any one to finish

Listing Processes  ps PID TTY TIME CMD 4073 pts/23 00:00:00 bash pts/23 00:00:00 ps  ps can be given different options to, e.g. list all processes on system, show the user that owns the process, etc.

Child and Parent Processes  Any process can create another process  That process is then a parent process of the newly created child process  Use the pstree command to view relationships between parent and child processes (the process tree)

pstree ~]$ pstree -p zuczpd gconfd-2(10782) kdeinit(10733)-+-artsd(10752) |-emacs(10779)---aspell(27099) |-kdeinit(10738) |-kdeinit(10771)---bash(10783)---emacs(23700)-+-aspell(32542) | `-emacsserver(23754) |-kdeinit(10773) |-kdeinit(10774)---bash(10802) |-pam-panel-icon(10768)---pam_timestamp_c(10770) `-xload(10778)

Child and Parent Processes (2)  A parent process forks to create a child process  This allows multiprocessing: $ $ pwd $$ pwd &$$ ls & $ ls Prompt Running Job 1 Running Job 2 Parent Process Child Process

 Children run separately and simultaneously with each other and with their parents (although the parent might choose to wait for its child to finish)  Children inherit from their parents  When a process spawns to make a child process, the child is initially an exact copy of the parent, except for some differences (see next) Child and Parent Processes (3)

Differences between Child and Parent Processes  They have different Process IDs (PIDs)  The have different PPIDs (parent PIDs)  Accounting information is reset for the child  For details of all the differences look up the manual page on the system call fork  All other things are initially the same, but each process has its own copy (they can modify their own copy)

Being “nice” to other people!  If you are running a program on a shared machine and you know it will take some time - “nice” it  nice will run a program at a lower priority so that it doesn’t clog up the CPU  Priorities range from 19 to -20  -20 is the highest priority, but you are not allowed to set priorities below 0 unless you are root $ nice –n 20 find. -name unix.ps –print

Job Control: top  A program which shows you information about the top CPU processes  Updates this information at regular intervals  Type q to quit  Type k to kill a process (to kill means to send a signal)  Type u (return) followed by a username (return) to just see the processes belonging to that user

Killing Processes  Use top  Alternatively, use kill  kill  E.g. kill  “-15” is the signal number – here, it means “stop the process cleanly” (i.e. close any files it is using)  More about signals later…  “-9” means “kill the process whatever”  Useful if all else fails!  killall will send the signal to every process with that name.

Process States  Processes can have one of a number of states:  0 - running on a processor  S - sleeping (waiting for an event to complete)  R - runnable (process is on run queue)  Z – zombie

Running a Process in the Background  Some commands may take a while to complete  Some may run until the user Exits (e.g. emacs)  You may want to use your command line in the meantime:  & puts a process in the background (detaches it from the terminal)  E.g. emacs &

Suspending Processes  Processes can be temporarily suspended  Use Ctrl-Z  To restart a process type one of:  fg (puts process back in the foreground)  bg (will restart process, but in the background)  Suspended processes can also be killed:  Do a process listing  Use the kill command with the process ID

Job Control  The jobs command produces a numbered list of background and suspended processes  You can use these job numbers to access your jobs:  Note that the job number is not the process ID! ~]$ jobs [1] - Runningxclock -d [2] + Suspendedmore temp.txt ~]$ kill %2 ~]$ jobs [1] - Runningxclock -d [3] Terminatedmore temp.txt

Job Control (2)  jobs allows you to:  Bring a job to the foreground  fg %  Run a job in the background  bg %  Suspend a job  stop %  Terminate a job  kill %

Control Key Sequences for Processes  Some control sequences affect processes:  Ctrl-C - kill a process  Ctrl-D - exit a shell (send EOF)  Ctrl-S - suspend or pause the display of output  Ctrl-Q - resume or continue output from Ctrl-S

Daemons  UNIX daemons are processes which lie dormant until they are needed for a particular service (services in windows- speak)  Commonly, their names end with a ‘d’  Examples are:  Printer daemons (lpd)  Web server daemons (httpd)  Scheduling daemons (atd, crond)

Scheduling Processes - cron  Processes can be scheduled to run at a periodic intervals:  Use the cron daemon  With this, users can schedule processes to run periodically, or at specified times  Create a text file called crontab.cron which contains lines with a date/time and command line

Scheduling Processes - cron (2)  Cron jobs are allowed or denied by system administrators using the cron.allow and cron.deny files in either /var/spool/cron or /etc/crond.d  You have to register your crontab using the command crontab crontab.cron in order for the cron daemon to activate your crontab

Scheduling Processes - cron (3)  Each line in crontab.cron has five fields:  Minute - (0-59)  Hour - (0-23)  Day of the month - (1-31)  Month of the year - (1-12)  Day of the week - (0-6) (Sunday is 0)  Command line - the command to be executed

Using cron  Edit your crontab.cron file to contain what you want it to do:  This cron job will record the date it was run every 30 minutes from Monday to Friday, in the file datelog  Register your crontab: $ crontab crontab.cron 0,30 * * * 1-5 date >> datelog

Scheduling Processes - at  You can schedule something to happen once using at  at TIME will execute at given TIME the commands given in STDIN.  It’s often more comfortable to use at TIME < filename at TIME –f filename

Scheduling Processes - at (2) $ at now + 1 min $ at> who | logged $ at> ls myDir | listing.txt $ at> job a at Mon Feb 12 11:41: $ at 3am < commands job 8 at :00

Scheduling Processes - batch  The batch command can be used to queue up jobs:  These jobs will be run as soon as the system has the resources to do so $ batch at> ls myDir > listing.txt at> $

UNIX Signals  Signals are a UNIX mechanism for controlling processes  A signal is a message to a process that requires immediate attention  Signals are generated by exceptions, e.g.:  Attempts to use illegal instructions  The user pressing an interrupt key  Window resize events  A child process calling exit or terminating abnormally

Signal Numbers  Each signal has a default action associated with it  Most signals can be caught from within a program. A programmer can then:  Ignore signal  Perform the default action  Execute a program specified function  The default action can be  TermTerminate the process.  IgnIgnore the signal.  CoreTerminate the process and dump core.  StopStop the process.

Signal Numbers Signal Name NumberDefault Action Meaning SIGHUP1TermHangup (sent to a process when a modem or network connection is lost, terminal is closed, etc) SIGINT2TermInterrupt (generated by Ctrl-C) SIGTRAP5CoreTrace trap SIGKILL9TermKill SIGBUS10CoreBus error (invalid memory reference) SIGSEGV11CoreSegmentation violation SIGTERM15TermSoftware termination signal (default kill signal) For a complete reference see the section 7 of the manual on signal $ man 7 signal

Summary  UNIX processes  How to list them  How to prioritise them  How to schedule them  Parent and Child processes  Signals  What are they for?  Types of signal

Next Lecture UNIX Network utilities