Title: Getting Started with Linux: Novells Guide to CompTIAs Linux Course 3060
1Getting Started with Linux Novells Guide to
CompTIAs Linux (Course 3060)
- Section 8
- Processes, Jobs, and Runlevels
2Objectives
- Understand Processes and Jobs
- View Processes from the GUI and the Command-Line
Interface - Manage Jobs and Processes
- Understand Runlevel
- Schedule Tasks
3Understand Processes and Jobs
- To understand processes and jobs, you need to
know the following - Process Definitions
- Jobs and Processes
4Process Definitions
- These terms are used to describe Linux processes
- Program structured set of commands stored in an
executable file on a Linux file system - Process program running in memory and on the CPU
- User process process launched by a user that
runs from a terminal - Daemon process system process that is not
associated with a terminal - PID unique ID assigned to every process as it
begins - Child process process started by another process
- Parent process process that starts other
processes - PPID PID of the parent process of current process
5Process Definitions (continued)
6Process Definitions (continued)
7Jobs and Processes
- Each process is identified using a unique PID
- In Linux, you use a job ID to refer to processes
started from an interactive shell - In bash, jobs returns all processes that have
been started from that shell and run in the
background - All jobs have a PID, but not all processes have a
usable job ID - PID 1 always belongs to the init process
- When the maximum process number has been reached,
the next process is allocated the lowest
available number (such as PID 7494) - After one process has ended, its number again
becomes available
8View Processes from the GUI and the Command-Line
Interface
- In this objective, you learn how to do the
following - View Processes from the GUI
- View Processes from the Command-Line Interface
9View Processes from the GUI
Click to sort processes
Click to end a process
10View Processes from the GUI (continued)
11View Processes from the Command-Line Interface
- To view processes, you can use
- ps use to see running processes
- pstree displays a list of processes in the form
of a tree structure - pstree -up less
- lsof use to see which files are opened by
processes - top use to find out how much computing time
processes use
12View Processes from the Command-Line Interface ps
13View Processes from the Command-Line Interface
ps (continued)
14View Processes from the Command-Line Interface
ps (continued)
15View Processes from the Command-Line Interface
top
16View Processes from the Command-Line Interface
top (continued)
17Manage Jobs and Processes
- To control jobs and processes, you have to
understand how to - Control Jobs from the Shell
- Control Processes
18Control Jobs from the Shell
- Commands can run in foreground or in background
- Foreground processes can receive signals directly
- xeyes
- Use Ctrl z to stop process
- If you start a process in the background, the
shell is available for further input of commands - bg resumes a stopped program in the background
- fg jobID sends process to foreground
- xeyes
- job ID (2) and PID (10982) are returned
- jobs lists the contents of job control
19Control Processes
- To control processes, you have to know how to
- Control Processes Using Signals
- Prioritize Processes
- Manage a Daemon Process
20Control Processes Using Signals
- When a process receives a signal it can
- Capture the signal and react to it
- Ignore it if no function exists for handling that
signal - Processes do not have control over the following
signals as they are handled by the kernel - kill -SIGKILL or kill -9
- kill -STOP or kill -19
- kill 18734 or killall xeyes
- kill -SIGKILL PID or kill -9 PID
- For the kernel to forward the signal to a
process, it must be sent by the owner of the
process or by root
21Control Processes Using Signals (continued)
22Exercise 8-1 Control Processes from the GUI and
the Command Line
- If the system seems to react sluggishly, it is
helpful to be able to find out the likely cause - Various commands available for this purpose,
graphical as well as based on the command line - The purpose of this exercise is to familiarize
you with some of the available tools
23Prioritize Processes
- Linux distributes available computing time
equitably - To assign a process more or less computing time
- nice -n 5 sleep 99
- NI column in top list contains nice value of
process - Values -20 (high) to 19 (low) default is 0
(neutral) - Only root can start a process with negative nice
value - Use renice to change nice value of a running
process - renice 5 1712 (only root can reduce the nice
value) - top combines the functionality of ps and renice
- By typing r, you can adjust the priority of a
process
24Manage a Daemon Process
- Service process (or collection of) that waits
for an external event to trigger an action - Also called daemon (disk and execution monitor)
- Run in the background and are usually started
when system is booted - Types signal-controlled or interval-controlled
- For each, there is a script in /etc/init.d/ that
can be controlled and run with the parameters in
Table 8-8 - For many scripts, there is a symbolic link in
/usr/sbin/ or in /sbin/ - For example, /etc/init.d/sshd start or rcsshd
start
25Manage a Daemon Process (continued)
- Some important daemons include
- cron
- cupsd
- httpd
- sshd
- syslogd
26Manage a Daemon Process (continued)
27Exercise 8-2 Manage Linux Processes and Services
- Processes can run with different priorities,
leaving more (or less) resources for other
processes - Processes can run in the foreground or in the
background, independently from their priority - The purpose of this exercise is to show you how
you can influence the priorities of different
processes
28Understand Runlevel
- In this objective, you learn the following about
runlevels - The init Program
- The Runlevels
- init Configuration File (/etc/inittab)
- init Directories and Scripts
29The init Program
- The system is initialized by /sbin/init
- Controls booting up and shutting down of system
- signal 9 (SIGKILL) has no effect on init
- Main configuration file is /etc/inittab
- Determines what happens in the individual
runlevels - Entries indicate various scripts to be started
scripts are located in /etc/init.d/ (SLES 9) or
/etc/rc.d/init.d/ - In other distributions, /etc/rc.d/rc.local is run
by init after all other initialization is
complete - Use to add commands for your environment
30The Runlevels
- The runlevel defines the state of the system
- Entry initdefault in /etc/inittab (normally 3 or
5) - To change runlevel init runlevel
- runlevel displays the previous and current
runlevel - Can be changed at boot root/dev/hda4 vga791 1
31The Runlevels (continued)
32The Runlevels (continued)
- Switch to another runlevel using init init 3
- Useful if you encounter problems caused by a
particular service - Switch to a lower runlevel to repair the service
- If GUI freezes, press Ctrl Alt Backspace to
restart X - Or, switch to a text console (Ctrl Alt F1),
and as root issue init 3 and then init 5 - To shutdown or reboot system init 0 or init 6
- It is better to use commands in Table 8-10
- shutdown 5 The new hard drive has arrived
- shutdown -c
33The Runlevels (continued)
34The Runlevels (continued)
35Exercise 8-3 Work with Runlevels
- There is rarely a reason to change the runlevel
- The main reason is usually some maintenance work
- The purpose of this exercise is to teach you how
to change runlevels
36init Configuration File (/etc/inittab)
- Determines what happens on individual runlevels
- Entries start scripts in /etc/init.d/ (e.g.
/etc/init.d/rc) - Syntax of each line in /etc/inittab
idrlactionprocess - id5initdefault
- sibootwait/etc/init.d/boot
- l00wait/etc/init.d/rc 0
- l11wait/etc/init.d/rc 1
- l22wait/etc/init.d/rc 2
-
- lsSwait/etc/init.d/rc S
- Srespawn/sbin/sulogin
- cactrlaltdel/sbin/shutdown -r -t 4 now
- 12345respawn/sbin/mingetty --noclear tty1
- 22345respawn/sbin/mingetty tty2
37init Directories and Scripts
- boot
- boot.local
- boot.setup
- halt
- rc
To create your own scripts, you can use the file
/etc/init.d/skeleton as a template
38init Directories and Scripts (continued)
Files in /etc/init.d/rc3.d/ (for runlevel 3)
39init Directories and Scripts (continued)
40init Directories and Scripts (continued)
- When changing runlevels
- If there is a Kxx link for a service in
/etc/init.d/rccurrentrl.d/ - If there is Sxx link in /etc/init.d/rcnewrl.d/
for service do nothing else service is stopped - Else, if there is Sxx link in /etc/init.d/rcnewrl.
d/ for service, service is started
41init Directories and Scripts (continued)
42Activate and Deactivate Services for a Runlevel
- Services in a runlevel can be activated/deactivate
d from the command line with insserv or using
YaST - You can create symbolic links in the runlevel
subdirectories, but it is easier to edit script
header - After editing the INIT INFO block, enter insserv
- To disable a service, stop service and enter
insserv -r service
43Exercise 8-4 Enable Services
- Depending on the purpose of the machines, certain
services have to be available, whereas others
have to be turned off - There are convenient ways to activate or
deactivate services in SLES 9 and the purpose of
this exercise is to familiarize you with them - Part I Enable Services Using chkconfig and
insserv - Part II Use YaST to Enable Services
- When administering SLES 9, you should make up
your mind as to which method to use - Mixing chkconfig/ insserv and YaST to administer
services is not advisable
44Schedule Tasks
- Most SLES 9 administrators and regular users find
that they need to complete certain tasks
regularly on a running system (such as updating a
database or backing up data) - You can automate these jobs in Linux by doing the
following - Schedule a Job (cron)
- Run a Job One Time Only (at)
45Schedule a Job (cron)
- You can schedule jobs to be run on a regular
basis by using the service cron (/usr/sbin/cron) - Service runs as a daemon and checks once a minute
to see if jobs have been defined for the current
time - By default, the service should be activated
- A crontab file contains the list of jobs
- A crontab exists for the entire system as well as
for each user defined on the system
46System Jobs
- You control system jobs with the file
/etc/crontab - The cron jobs that are defined here after
installation run the scripts contained in Table
8-12 - Do not delete lines from crontab added at
installation - Jobs are run later if they could not be run at
the specified time - /var/spool/cron/lastrun/
47System Jobs (continued)
- These are standard shell scripts
- They are overwritten when you update your system
- Store modifications in /root/bin/cron.daily.local
(not overwritten when on system update) - Store other files for system jobs in /etc/cron.d/
- Use same format as /etc/crontab
- Jobs defined here are not run automatically at a
later time
48User Jobs
- To allow users to configure cron jobs, use
- /var/spool/cron/allow
- /var/spool/cron/deny
- By default, contains entries like guest and gast
- The jobs of a user are in /var/spool/cron/tabs/use
r - These files belong to root
- Use crontab to edit them
49User Jobs (continued)
50User Jobs (continued)
- Each line in a file defines a job
- /10 8-17 1-5 fetchmail mailserver
- From Monday to Friday, every 10 minutes between
800 A.M.-500 P.M., fetchmail mailserver is
run - For system jobs, specify the user with
permissions to run it, by entering its name
between the time details and the name of the
command
51Run a Job One Time Only (at)
- at runs a job one time only
- Make sure the service atd is started
- Use /etc/at.allow and /etc/at.deny
- Syntax at launch_time
- To use a file at f file launch_time
52Run a Job One Time Only (at, continued)
53Exercise 8-5 Schedule Jobs with cron and at
- Scheduling jobs with cron is a very common task
- It can make system administration much easier to
have certain regular tasks like backups run
automatically outside working hours - at is very handy for one-time tasks
- The purpose of this exercise is for you to use
the available tools for scheduling tasks - In this exercise, you do the following
- Part I Schedule Jobs with at
- Part II Schedule Jobs with cron
54Summary
- Processes are programs executing on the system
- Every process has a PID, a PPID, and can possibly
start an unlimited number of child processes - The first process loaded by the kernel is the
init daemon, which always has a PID of 1 - Background processes have a job ID that you can
use to control their execution - You can view processes within a desktop
environment by using the KDE System Guard, or at
a command prompt by using the ps, pstree, lsof,
and top commands
55Summary (continued)
- The KDE System Guard and the kill, killall, and
top commands can be used to stop processes by
sending them signals - You can affect the priority of a process by
changing its nice value - nice allows user to set the priority of a program
and run it - Daemons may be started by running the appropriate
script in /etc/init.d with the start argument, or
by using the rcdaemonname start command - A Linux system is categorized using runlevels
56Summary (continued)
- The init daemon is responsible for loading and
unloading daemons, using the file /etc/inittab - /etc/inittab runs scripts that start with S
(start) or K (kill) in the /etc/init.d/rc.d when
changing runlevels - You can view your current runlevel using the
runlevel command, and force the init daemon to
change runlevels using the init command - Commands may be scheduled to run at a later time
using the at daemon - To schedule tasks to occur regularly in the
future, you must use the cron daemon to create a
crontab