RH030 Linux Computing Essentials

Slides:



Advertisements
Similar presentations
Job and Process Management
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.
Essential System Administration 3rd Edition Chapter 2 The Unix Way(Cont.) University Of Palestine.
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.
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.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
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?
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.
Linux in More Detail Shirley Moore CPS5401 August 29,
Guide to Linux Installation and Administration, 2e1 Chapter 8 Basic Administration Tasks.
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
Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources.
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.
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.
Guide To UNIX Using Linux Third Edition Chapter 8: Exploring the UNIX/Linux Utilities.
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.
System calls for Process management
Guide to Linux Installation and Administration, 2e1 Chapter 11 Using Advanced Administration Techniques.
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,
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
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.
PTA Linux Series Copyright Professional Training Academy, CSIS, University of Limerick, 2006 © Workshop VI Scheduling & Process Management Professional.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 2.
System calls for Process management Process creation, termination, waiting.
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.
Unix System Administration Controlling Processes Chapter 5.
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.
Lesson 8-Specifying Instructions to the Shell. Overview An overview of shell. Execution of commands in a shell. Shell command-line expansion. Customizing.
Processes Todd Kelley CST8207 – Todd Kelley1.
Chapter 6: Managing Processes
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
Structure of Processes
The Linux Command Line Chapter 10
CHAPTER 8 ( , ) John Carelli, Instructor Kutztown University
CSC 140: Introduction to IT
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Controlling Processes
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes – Part I.
Lab 6: Process Management
Process Management and System Monitoring
Process Description and Control in Unix
Lecture 6 Introduction to Process Management
LPI Linux Certification
Presentation transcript:

RH030 Linux Computing Essentials Workbook 9 Managing Processes RH030 Linux Computing Essentials

Linux+ Guide to Linux Certification, 2e Objectives Today is all about understanding processes on a Linux system Viewing processes local processes system processes Terminating Processes Kill Commands Using kill signals Modifying Processes Running background processes Modify the priority of a process Schedule commands: at crondtab Linux+ Guide to Linux Certification, 2e

Linux+ Guide to Linux Certification, 2e Chapter 1 A process is an instance of a running executable, identified by a process id (pid). It maintains a set of imformation relevant to the processes Such as virtual memory addresses, every process possesses its own distinct memory context. A process has a uid and a collection of gid as credentials. A process has a filesystem context, including a cwd, a umask, a root directory, and a collection of open files. A process has a scheduling context, including a niceness value. A process has a collection of environment variables. The ps command can be used to examine all currently running processes. The top command can be used to monitor all running processes. Linux+ Guide to Linux Certification, 2e

Linux+ Guide to Linux Certification, 2e Linux Processes Linux manages tasks using processes Processes are programs that are executing on the system A program is really just a structured set of commands stored in an executable file which runs in memory and on CPU A Process can spawn a subprocess, thus creating a process hierarchy with parent / child relationships Some simple commands, such as cd, are executed by the shell itself and so do not create a separate process Each program creates a process which is assigned a unique process identification number (PID) Linux+ Guide to Linux Certification, 2e

Kernel Allocation for Processes Processes are run by the CPU Linux+ Guide to Linux Certification, 2e

All processes are generated. User process: Task is begun by a local user Task is run as a process owned by the user from the local terminal This process is now associated with that specific user. User processes are run from the same terminal as the user who executed them. “ tty? “ or “ pty? “- from ps output identifies it as a user process System process: System processes have been started by the kernel Or they are a service which has been turned on. They are not associated with a terminal Services are run by a Daemon process Which commonly run a network service “ ? “ - from the ps output identifies it as a system process Linux+ Guide to Linux Certification, 2e

Linux+ Guide to Linux Certification, 2e Viewing Processes ps command: Most commonly used command to view processes. No arguments: List local processes only Brief listing only PID, TTY, CPU time, command that started process, – f (full) option: Full detailed listing User identifier (UID), PID, PPID, TTY, start time, CPU utilization, command – u option: See the processes that another user is using. Linux+ Guide to Linux Certification, 2e

Overview of the ps Command $ ps [-options] Linux+ Guide to Linux Certification, 2e

ps –f gives full output details See examples page 436 A full listing shows both PID and PPID Linux+ Guide to Linux Certification, 2e

Viewing All Processes Running on the System ps – ef command: -e Lists all processes running on the system Brief listing only PID, TTY, CPU time, command that started process, –f (full) option: Full detailed listing User identifier (UID), PID, PPID, start time, TTY, CPU utilization, command Or you can use ps – aux command: Linux+ Guide to Linux Certification, 2e

SystemV verse BSD options page 441 Table 10-1: Common options to the ps command Linux+ Guide to Linux Certification, 2e

Linux+ Guide to Linux Certification, 2e ps –ef Command Output Linux+ Guide to Linux Certification, 2e

Linux+ Guide to Linux Certification, 2e pgrep [maxwell@station maxwell]$ pgrep -l sshd 829 sshd [maxwell@station maxwell]$ pgrep -lu maxwell 2112 bash 2146 mozilla-bin 2155 mozilla-bin 2156 mozilla-bin 2157 mozilla-bin Linux+ Guide to Linux Certification, 2e

Filtering ps command Output See example page 438 Output from a ps –ef listing can be quite long By piping the output of the ps command through grep you can search for the specific process you want to terminate and determine the correct PID Linux+ Guide to Linux Certification, 2e

Linux+ Guide to Linux Certification, 2e Chapter 2 Key Concepts In Linux, the first process, /sbin/init, is started by the kernel on bootup. All other processes are the result of a parent process duplicating itself, or forking. A process begins executing a new command through a process called execing. Often, new commands are run by a process (often a shell) first forking, and then execing. This mechanism is referred to as the fork and exec mechanism. Processes can always be found in one of five well defined states: runnable, voluntarily sleeping, involuntarily sleeping, stopped, or zombie. Process ancestry can be viewed with the pstree command. When a process dies, it is the responsibility of the process's parent to collect it's return code and resource usage information. When a parent dies before it's children, the orphaned children are inherited by the first process (usually /sbin/init). Linux+ Guide to Linux Certification, 2e

How Linux Manages Processes page 435 During the boot, the first 2 main system processes are started sched (scheduler) (pid 0) init (initialization) (pid 1) which manages all other processes Figure 10-2: Process genealogy Linux+ Guide to Linux Certification, 2e

One process can start another process All Processes require a unique ID within the system. PID = Unique identifier assigned to a process Child process: (PID): Process started by another process Parent Process ID (PPID): Process that has started another process Figure 10-1: Parent and child processes Linux+ Guide to Linux Certification, 2e

There are different types of processes Daemon System processes that exist for a specific system purpose httpd daemon - exists for the sole purpose of handling internet services, running inactive in the background until needed Parent A process which has spawned another process Following boot-up, a process called init is invoked Every process, except init, has a parent process Child process spawned by another process Except for init all other processes are a child processes of a parent process Linux+ Guide to Linux Certification, 2e

Types of (troubled) Processes Orphan Created when a child process is running and the parent process is killed. The system recognises the orphaned child process. And passes the orphan process to init which then becomes the it’s new parent process and terminates it. Zombie (or Defunct) Created when a child process loses it’s connection to an existing parent process. It keeps running but becomes “lost” in the system And so cannot be terminated by it’s parent process. It just keeps running forever. Keeps using system resource by using a slot in the process table; It cannot be stopped in a conventional manner The only way to kill a zombie is to reboot the system Linux+ Guide to Linux Certification, 2e

Linux+ Guide to Linux Certification, 2e Process states ps -aux Current processor state of process Most processes are either sleeping (S) or running (R) Zombie process state is Z Linux+ Guide to Linux Certification, 2e

Linux+ Guide to Linux Certification, 2e /proc The ps command gets it’s info from /proc /proc is a system directory created at installation It is always created under the / directory It is similar to the windows device manager It holds system information. The process information for each processes is stored in the /proc system directory using it’s PID. The ps commands is used to view this information Linux+ Guide to Linux Certification, 2e

Viewing “Top” Processes top command: Displays interactive screen listing processes Organized by processor time Processes using most processor time listed first Identify Rogue process: Faulty process Consumes excessive system resources top command can be used to change a processes priority or terminate a processes. Linux+ Guide to Linux Certification, 2e

Chapter 3 - Process Scheduling: nice and renice Key Concepts A primary task of the Linux kernel is scheduling processes. Every process has a niceness value that influences its scheduling. The nice and renice commands can change a process's scheduling priority. Linux+ Guide to Linux Certification, 2e

Process priority & niceness Every process has two values which influence its scheduling. The first is a dynamic value which is constantly being changed by the kernel as the process's priority. The second is a fixed value, which is only occasionally (if ever) explicitly changed by a user is the process's niceness. nice command: Change a process’s niceness as it starts nice +13 vi myfile.txt renice command: Alter niceness of a process after it is running Only root user may change NI to a negative value nice 19 1426 Linux+ Guide to Linux Certification, 2e

Setting Process Priority (PRI) Nice value (NI): Indirectly represents priority Determines how many processor time slices the process will receive. Higher value means lower priority EXAMPLE nice +13 vi myfile.txt runs the vi command on myfile.txt with an increment of +13. Linux+ Guide to Linux Certification, 2e

Chapter 4 - Sending Signals Key Concepts Signals are a low level form of inter-process communication, which arise from a variety of sources, including the kernel, the terminal, and other processes. Signals are distinguished by signal numbers, which have conventional symbolic names and uses. The symbolic names for signal numbers can be listed with the kill -l command. The kill command sends signals to other processes. Upon receiving a signal, a process may either ignore it, react in a kernel specified default manner, or implement a custom signal handler. Conventionally, signal number 15 (SIGTERM) is used to request the termination of a process. Signal number 9 (SIGKILL) terminates a process, and cannot be overridden. The pkill and killall commands can be used to deliver signals to processes specified by command name, or the user who owns them. Other utilities, such as top and the GNOME System Monitor can be used to deliver signals as well. Linux+ Guide to Linux Certification, 2e

Linux+ Guide to Linux Certification, 2e It is often necessary to kill parent process in order to kill a child process Killing a parent process will kill all child processes spawned by it. Such as if you wished to kill all the spawned child processes. Use the output from the ps command. Look at the output from ps command and use it read the PID and PPID information. Tracing from the child process up the hierarchy to the parent processes. Linux+ Guide to Linux Certification, 2e

Terminating processes You can terminate a process using the kill, killall, top See examples p444 kill command: Kills all instances of a specific process By PID Or by command name killall command: Uses process name instead of PID Kills all instances of a process by command name Linux+ Guide to Linux Certification, 2e

Kill Signals kill –l Table 10-2: Common administrative kill signals Displays a list of all the possible kill signals. 64 different kill signals Affect processes in different ways Table 10-2: Common administrative kill signals Linux+ Guide to Linux Certification, 2e

Linux+ Guide to Linux Certification, 2e Kill Signals kill –signal command: To kill a process, give kill signal and PID If no kill signal given, SIGTERM ( 15) assumed $ kill -15 soft kill If process will not terminate SIGKILL ( 9 ) can be used to force it. $ kill -9 absolute kill Linux+ Guide to Linux Certification, 2e

Linux+ Guide to Linux Certification, 2e Chapter 5. Job Control Key Concepts The bash shell allows commands to be run in the background as "jobs". The bash shell allows one job to run in the foreground, and can have multiple backgrounded jobs. The jobs command will list all backgrounded jobs. The CTRL-Z key sequence will suspend and background the current foreground job. The bg command resumes a backgrounded job. The fg command brings a backgrounded job to the foreground. Linux+ Guide to Linux Certification, 2e

Linux+ Guide to Linux Certification, 2e Running Processes There are 2 areas in which processes can be run. Foreground processes: BASH shell must wait for process termination to continue Background processes: BASH shell does not wait for termination to continue Processes can be run in the background by appending an & to the command name When “ & “ is placed at the end of a command it causes the command to be run in the background upon execution. The user receives a BASH shell prompt immediately. Linux+ Guide to Linux Certification, 2e

Background /Foreground processes See examples p447 jobs command: Lists background processes running in current shell Each background jobs is given a specfic “ %# “ by which it is referred. It also marks the two most recent background processes Commands operate on most recent process, by default + symbol = most recent process - symbol = next most recent process foreground (fg) command: Run move a background process into the foreground fg %1 background (bg) command: To run a job in the background place a “ & “ at the end of the command-line vi my-document & Or type “ ctrl Z” to move a running foreground process into the background Linux+ Guide to Linux Certification, 2e

Chapter 6. Scheduling Delayed Tasks: at Key Concepts The at command can submit commands to run at a later time. The batch command can submit commands to run when the machines load is low. Commands can either be entered directly, or submitted as a script. stdout from at jobs is mailed to the user. atq and atrm are used to examine and remove currently scheduled jobs. Linux+ Guide to Linux Certification, 2e

Linux+ Guide to Linux Certification, 2e Scheduling Commands Commands can be scheduled to run at a later time Using the at or cron daemons. at daemon (atd): System daemon that executes tasks at a future time cron daemon (crond): System daemon that executes tasks repetitively in the future Linux+ Guide to Linux Certification, 2e

Scheduling Commands with atd See examples page 452 - 455 at <time> command: Used to schedule commands to run at a preset time. Runs command once only. Example: at now cp /etc/passwd ~/atpass Table 10-3: Common at commands Linux+ Guide to Linux Certification, 2e

Viewing Scheduled “ at “ Jobs Shell environment & scheduled commands are stored in /var/spool/at Used to allow us to view scheduled jobs queue. The “ at “ daemon uses current shell’s environment for execution If stdout of scheduled command has not been redirected to file, It is mailed to user atq command: Each local users has their own “ at “ queue. Regular users can only see their own jobs. –l option: View the queued list of scheduled jobs –c option: View system environment at scheduling time –d option: Delete a job –f option: Run scheduled jobs from shell script Linux+ Guide to Linux Certification, 2e

Chapter 7. Scheduling Periodic Tasks: cron Key Concepts The cron facility is used to schedule regularly recurring tasks. The crontab command provides a frontend to editing crontab files. The crontab file uses 5 fields to specify timing information. stdout from cron jobs is mailed to the user. Linux+ Guide to Linux Certification, 2e

Scheduling Commands with crond See examples page 457 – 459 crontab command: Used to schedule commands on a preset schedule. Local users can view and edit their own cron tables Six fields separated by space or tab characters which determine action –e option: Edit cron tables in vi editor –l option: List a user cron table –r option: Remove all scheduled jobs Linux+ Guide to Linux Certification, 2e

Example crond table entry Figure 10-6: Sample user cron table entry Linux+ Guide to Linux Certification, 2e

Linux+ Guide to Linux Certification, 2e Summary ps ps –f -e ps –ef | grep PID kill killall jobs fg bg kill %1 nice renice at crontab Linux+ Guide to Linux Certification, 2e