Upload
ashwin-josiah-samuel
View
221
Download
0
Embed Size (px)
Citation preview
8/16/2019 Chapter-8-Process in Linux System
1/44
Chapter 8
Process in Linux System
8/16/2019 Chapter-8-Process in Linux System
2/44
VIEW AND M ANAGE PROCESSES
To manage processes you need to know the following:
Understand Process Definitions
Learn Jobs and Processes
Manage Foreground and Background Processes View and Prioritize Processes
End a Process
Understand Services (Daemons)
Manage a Daemon Process
2
8/16/2019 Chapter-8-Process in Linux System
3/44
UNDERSTAND PROCESS DEFINITIONS
The following terms are used to describe Linux
processes:
Program — A structured set of commands stored in an
executable file on a Linux file system
Process —
A program that is loaded into memory and
executed by the CPU
User process — A process launched by a user that is started
from a terminal or within the graphical environment
Daemon process —
A system process that is not associatedwith a terminal or a graphical environment
3
8/16/2019 Chapter-8-Process in Linux System
4/44
4
Figure 10-2 Relationship between daemon processes and user processes
8/16/2019 Chapter-8-Process in Linux System
5/44
UNDERSTAND PROCESS DEFINITIONS
(CONTINUED)
Properties of a process:
Process ID (PID)
Child process
Parent process Parent Process ID (PPID)
5
8/16/2019 Chapter-8-Process in Linux System
6/44
UNDERSTAND PROCESS DEFINITIONS
(CONTINUED)
6
Figure 10-3 The relationship between parent and child process ID numbers
8/16/2019 Chapter-8-Process in Linux System
7/44
LEARN JOBS AND PROCESSES
Job identifier (job ID)
A numeric value that identifies the running program
uniquely within that shell
Each process is identified using a process ID (PID) thatis unique across the entire system
All jobs have a PID, but not all processes have a usable
job ID
PID 1 always belongs to the init process When performing tasks such as changing the priority
level of a running program, use the PID
7
8/16/2019 Chapter-8-Process in Linux System
8/44
M ANAGE FOREGROUND AND B ACKGROUND
PROCESSES
Processes executed in the foreground
Started in a terminal window and run until the process is
completed
Background process execution Occurs when a process is started and the terminal window
returns to a prompt before the process finishes executing
Existing processes can be switched from foreground to
background execution
8
8/16/2019 Chapter-8-Process in Linux System
9/44
M ANAGE FOREGROUND AND B ACKGROUND
PROCESSES (CONTINUED)
Commands in a shell can be started in the foreground
or in the background
Continue running a stopped process in the background
by entering bg Appending an ampersand to a command starts the
process in the background
Each process started from the shell is assigned a job ID
by the job control of the shell Switch a process to the foreground by entering fg
job_ID
9
8/16/2019 Chapter-8-Process in Linux System
10/44
VIEW AND PRIORITIZE PROCESSES
ps
View running processes with the ps (process status)
command
10
Table 10-8 Some commonly used options with ps
8/16/2019 Chapter-8-Process in Linux System
11/44
VIEW AND PRIORITIZE PROCESSES
(CONTINUED)
11
Table 10-9 Some of the fields (columns) in the process list
8/16/2019 Chapter-8-Process in Linux System
12/44
VIEW AND PRIORITIZE PROCESSES
(CONTINUED)
12Table 10-10 Values for the STAT process state
8/16/2019 Chapter-8-Process in Linux System
13/44
VIEW AND PRIORITIZE PROCESSES
(CONTINUED)
pstree
Displays a list of processes in the form of a tree structure
Gives you an overview of the hierarchy of a process
nice and renice The nice command assigns a process a specific nice value
that affects the calculation of the process priority
The lower the value of the nice level, the higher the priority
of the process
13
8/16/2019 Chapter-8-Process in Linux System
14/44
VIEW AND PRIORITIZE PROCESSES
(CONTINUED)
nice and renice (continued)
The nice level is used by the scheduler to determine how
frequently to service a running process
Use the command renice to change the nice value of a
running process
top
Allows you to watch processes continuously in a list that is
updated in short intervals
Provides a real-time view of a running system
Can also be used to assign a new nice value to running
processes or to end processes
14
8/16/2019 Chapter-8-Process in Linux System
15/44
15
Figure 10-4 The output of the top command
8/16/2019 Chapter-8-Process in Linux System
16/44
END A PROCESS
kill and killall
The killall command kills all processes with an indicated
command name
The kill command kills only the indicated process
GNOME System Monitor
Start the GNOME System Monitor utility (Computer >More
Applications > GNOME System Monitor) to view and kill
processes
16
8/16/2019 Chapter-8-Process in Linux System
17/44
END A PROCESS (CONTINUED)
17
Table 10-13 The more commonly used kill signals
8/16/2019 Chapter-8-Process in Linux System
18/44
18
Figure 10-5 The GNOME System Monitor utility
8/16/2019 Chapter-8-Process in Linux System
19/44
END A PROCESS (CONTINUED)
19
Table 10-14 Information displayed by default on the Process tab
8/16/2019 Chapter-8-Process in Linux System
20/44
UNDERSTAND SERVICES (D AEMONS)
A service is also called a daemon
Process or collection of processes that wait for an event to
trigger an action on the part of the program
Network-based services create a listener on a TCP orUDP port when they are started
Listener waits for network traffic to appear on the
designated port
When traffic is detected, the program processes the trafficas input and generates output that is sent back to the
requester
20
8/16/2019 Chapter-8-Process in Linux System
21/44
M ANAGE A D AEMON PROCESS
Daemons run in the background and are usually
started when the system is booted
Daemons make a number of services available
Daemons are terminal-independent processes, and areindicated in the ps x TTY column by a ?
Two types of daemons are available:
Signal-controlled daemons
Interval-controlled daemons
21
8/16/2019 Chapter-8-Process in Linux System
22/44
M ANAGE A D AEMON PROCESS (CONTINUED)
Each daemon has a corresponding script in /etc/init.d/
Many scripts have a symbolic link in either the
/usr/sbin/ directory or the /sbin/ directory
Find configuration files for daemons in the /etc/
directory or in its subdirectories22
Table 10-15 Parameters used to control daemon scripts
8/16/2019 Chapter-8-Process in Linux System
23/44
M ANAGE A D AEMON PROCESS (CONTINUED)
Some important daemons:
cron — Starts other processes at specified times
cupsd — The printing daemon
sshd —
Enables secure communication by way of insecurenetworks (secure shell)
syslog ng — Logs system messages in the directory /var/log/
23
8/16/2019 Chapter-8-Process in Linux System
24/44
M ANAGE LINUX PROCESSES
In this exercise, start and stop processes and change
their priorities
First, start and suspend xeyes, move it to the
background and foreground, and stop it
Then, start xeyes and set the priority of the running
program to a nice value of -5
Start a second xeyes with a nice value of 10
24
8/16/2019 Chapter-8-Process in Linux System
25/44
SCHEDULE JOBS
Automate jobs in Linux by doing the following:
Schedule a Job (cron)
Run a Job One Time Only (at)
25
8/16/2019 Chapter-8-Process in Linux System
26/44
SCHEDULE A JOB (CRON)
Schedule jobs to be carried out on a regular basis by
using the cron service (/usr/sbin/cron)
The service runs as a daemon
Checks once a minute to see if jobs have been defined for
the current time
A file that contains the list of jobs is called a crontab
A crontab exists for the entire system as well as for each
user defined on the system The /etc/sysconfig/cron file contains variables for the
configuration of some scripts started by cron26
8/16/2019 Chapter-8-Process in Linux System
27/44
SCHEDULE A JOB (CRON) (CONTINUED)
System jobs
Control system jobs with the /etc/crontab file
Can add lines to /etc/crontab, but do not delete the lines
added at installation
Information on the last time the jobs were run is kept in
the /var/spool/cron/lastrun/ directory 27
Table 10-16 Directories containing system jobs that will be run by cron
8/16/2019 Chapter-8-Process in Linux System
28/44
SCHEDULE A JOB (CRON) (CONTINUED)
User jobs
The jobs of individual users are stored in the
/var/spool/cron/tabs/ directory
In files matching the usernames Users create their own jobs using crontab
28Table 10-17 Options for the crontab command
8/16/2019 Chapter-8-Process in Linux System
29/44
SCHEDULE A JOB (CRON) (CONTINUED)
User jobs (continued)
Each line in a file defines a job
There are six fields in a line
29
Table 10-18 Fields in a crontab file
8/16/2019 Chapter-8-Process in Linux System
30/44
RUN A JOB ONE TIME ONLY ( AT)
If you want to run a job one time only, use the at
command
To use at, make sure the atd service is started
(rcatdstart) Two files determine which users can run this
command:
/etc/at.allow
/etc/at.deny Can modify or create these text files
30
8/16/2019 Chapter-8-Process in Linux System
31/44
RUN A JOB ONE TIME ONLY ( AT)
(CONTINUED)
If the /etc/at.allow file exists, only this file is evaluated
If neither of these files exists, only the user root can define jobs with at
Example:
31
8/16/2019 Chapter-8-Process in Linux System
32/44
SCHEDULE JOBS WITH AT AND CRON
In this exercise, schedule jobs with at and cron
First, redirect the output of finger to /var/log/messages
three minutes from the current time
Then, schedule the same job for tomorrow at noon
Then, schedule a program to run tomorrow at 2:00
p.m., and afterwards remove the job
In the second part of the exercise, create a cron job as
a normal user that logs the output of finger to
~/users.log every minute
32
8/16/2019 Chapter-8-Process in Linux System
33/44
M ANAGE RUNLEVELS
Managing runlevels is an essential part of Linux
system administration
In this objective, you learn what runlevels are, the role
of the program init, and how to configure and changerunlevels:
The init Program and Linux Runlevels
init Scripts and Runlevel Directories
Change the Runlevel
33
8/16/2019 Chapter-8-Process in Linux System
34/44
THE INIT PROGRAM AND LINUX
RUNLEVELS
The init program
The system is initialized by /sbin/init
Started by the kernel as the first process of the system
This process, or one of its child processes, starts alladditional processes
SIGKILL has no effect on init
The configuration file for init is /etc/inittab
Part of the configuration in /etc/inittab is the runlevel the
system uses after booting
34
8/16/2019 Chapter-8-Process in Linux System
35/44
THE INIT PROGRAM AND LINUX RUNLEVELS
(CONTINUED)
The runlevels
Runlevels define the state of the system
35Table 11-1 The available runlevels
8/16/2019 Chapter-8-Process in Linux System
36/44
THE INIT PROGRAM AND LINUX
RUNLEVELS (CONTINUED)
Init configuration file (/etc/inittab)
Each line in the /etc/inittab file uses the following syntax:id:rl:action:process
The first entry in the /etc/inittab file contains the following
parameters: id:5:initdefault:
The next entry in /etc/inittab looks like this:si::bootwait:/etc/init.d/boot
The next few entries describe the actions for runlevels 0 to 6
36
8/16/2019 Chapter-8-Process in Linux System
37/44
INIT SCRIPTS AND RUNLEVEL
DIRECTORIES
/etc/inittab defines the runlevel the system uses after
booting is complete
init scripts
The /etc/init.d/ directory contains shell scripts that are used
to perform certain tasks at bootup and start and stop
services in the running system
The shell scripts can be called up in the following ways:
Directly by init when you boot the system
Indirectly by init when you change the runlevel Directly by /etc/init.d/script parameter
37
8/16/2019 Chapter-8-Process in Linux System
38/44
INIT SCRIPTS AND RUNLEVEL DIRECTORIES
(CONTINUED)
38Table 11-2 /etc/init.d/script parameters
8/16/2019 Chapter-8-Process in Linux System
39/44
INIT SCRIPTS AND RUNLEVEL
DIRECTORIES (CONTINUED)
init scripts (continued)
Some of the more important scripts stored in /etc/init.d/:
boot
boot.local
halt
rc
service
39
8/16/2019 Chapter-8-Process in Linux System
40/44
INIT SCRIPTS AND RUNLEVEL
DIRECTORIES (CONTINUED)
Runlevel symbolic links
To enter a certain runlevel, init calls the /etc/init.d/rc script
with the runlevel as a parameter
This script examines the respective runlevel /etc/init.d/rcx.d/
directory and starts and stops services depending on thelinks in this directory
Each runlevel has a corresponding subdirectory in
/etc/init.d/
40
8/16/2019 Chapter-8-Process in Linux System
41/44
41
Figure 11-6 The YaST Runlevel Editor module
8/16/2019 Chapter-8-Process in Linux System
42/44
42
Figure 11-7 The YaST Runlevel Editor module in expert mode
8/16/2019 Chapter-8-Process in Linux System
43/44
INIT SCRIPTS AND RUNLEVEL
DIRECTORIES (CONTINUED)
Activate and deactivate services for a runlevel
(continued)
Normally, the default runlevel of a SUSE Linux system is
runlevel 5
Changes to the default runlevel take effect the next time you bootyour computer
To configure a service, select a service from the list
Then, from the options below the list, select the runlevels you want
associated with the service
43
8/16/2019 Chapter-8-Process in Linux System
44/44
CHANGE THE RUNLEVEL
Change the runlevel at boot
Possible to boot to another runlevel by specifying the
runlevel on the kernel command line of GRUB
Manage runlevels from the command line
Can change to another runlevel once the system is runningby using the init command
Like most modern operating systems, Linux reacts
sensitively to being switched off without warning The shutdown command shuts down the system after the
specified time
44