intro unix/linux 10

30
Lesson 10-Controlling User Processes

Upload: duquoi

Post on 19-May-2015

3.514 views

Category:

Technology


3 download

DESCRIPTION

controlling user processes

TRANSCRIPT

Page 1: intro unix/linux 10

Lesson 10-Controlling User Processes

Page 2: intro unix/linux 10

Overview

Managing and processing processes.

Managing jobs.

Exiting/quitting when jobs have been stopped.

Page 3: intro unix/linux 10

Managing and Processing Processes

Every running program is a separate entity, called a

process.

A process consists of several components working together,

including the code, data, CPU activity, memory, input,

output, and error handling.

Page 4: intro unix/linux 10

Managing and Processing Processes

Each process involves reading instructions, accessing

computer memory, reading from input, evaluating

arguments, performing calculations, and writing to output.

Every process on the system has its own unique process ID

number.

Page 5: intro unix/linux 10

Managing and Processing Processes

Obtaining detailed information on system processes.

Identifying processes connected to a terminal.

Starting a new shell process.

Obtaining detailed data about user processes.

Page 6: intro unix/linux 10

Genealogy of processes.

Ending foreground processes.

Ending background processes.

Terminating a process that is not responding.

Managing and Processing Processes

Page 7: intro unix/linux 10

Obtaining Detailed Information on System Processes

The “ps –aux” and the “ps –ef” commands can be used to

get a list of all processes currently running on the system.

The “ps –u $USER” command can be used to list only the

processes owned by a particular user.

The “ps –u root” command can be used to list the processes

that are started when the system is booted up, and that are

owned by the root user.

Page 8: intro unix/linux 10

Identifying Processes Connected to a Terminal

User processes must be informed of the port to which they

are attached.

The “tty” command can be used to determine the terminal

port used by a user.

The “ps –t port” command can be used to display the

running processes, the shell, a process running sleep, and

the process running the ps utility.

Page 9: intro unix/linux 10

Identifying Processes Connected to a Terminal

Output of ps Utility

Page 10: intro unix/linux 10

Identifying Processes Connected to a Terminal

PID – The PID, called the Process IDentification number, is a

unique number assigned to each process when it gets

created.

CPU – It refers to the CPU time consumed by a process.

CMD – The command mode contains the names of the

utilities associated with each running process.

Page 11: intro unix/linux 10

Starting a New Shell Process

The “sh” command is used to start a child shell.

The “echo $$” command can be used to obtain the PID of

the current shell.

The “exit” command or the CTRL-D keys can be used to exit

the child shell.

Page 12: intro unix/linux 10

Obtaining Detailed Data about User Processes

Output of ps –l Command

Page 13: intro unix/linux 10

Obtaining Detailed Data about User Processes

Flags (F) – This field contains a number indicating the Flags or

options set for a process.

State (S) – It indicates the state of the process, which includes

sleeping (S), running (R), idle (I), and traced (T).

Size (SZ) – It contains a number indicating the size of the

process in memory.

Command (CMD) – It refers to the actual command being run

by the process.

Page 14: intro unix/linux 10

Genealogy of Processes

Processes inherit data from their parent process.

Every utility or executable file name that is typed is

executed by a process that is a child of the shell process.

The child process inherits data such as tty, user ID, and the

current directory from the parent process.

Page 15: intro unix/linux 10

Ending Foreground Processes

The “stty –a” command can be used to display the settings

for a system.

The “echo $?” and the “echo $status” commands can be

used to ask for the exit status sent by the process running

sleep to the shell.

The “echo $?” command is used by the sh and the recent

csh family shells.

Page 16: intro unix/linux 10

Ending Foreground Processes

The “echo $status” command is used by the older csh

family of shells.

The CTRL-D key is used to mark the end-of-file character,

while the CTRL-C key is used to interrupt a process.

The CTRL-D key displays an output, but the CTRL-C does

not generate any output.

Page 17: intro unix/linux 10

Ending Foreground Processes

The keyboard signal “quit” can be used to stop a

foreground process.

The “CTRL-\” keys can also be used to quit a process.

The quit signal destroys the process and sometimes makes

a copy of the CPU memory associated with the process at

the time of exit. The copy is called a core file.

Page 18: intro unix/linux 10

Ending Background Processes

The “kill” command can be used to terminate a process

running in the background.

The command requires the PID of the process as the

second argument.

The “kill –l” command can be used to list all the kill signals

available for the current system.

Page 19: intro unix/linux 10

Ending Background Processes

Listing of All Signals

Page 20: intro unix/linux 10

Terminating a Process that is not Responding

The following tasks should be carried out to terminate a

process:

A new terminal should be started.

The current terminal port should be identified at the new

login or terminal.

All the processes should be listed.

The PID of the particular process should be identified and

the ‘kill’ command should be used to terminate it.

Page 21: intro unix/linux 10

Managing Jobs

A command-line that instructs the shell to start several

processes with the output from the first connecting to the

second and so on, is called a job.

All modern shells allow users to start, suspend, make

active, and kill the processes associated with a job.

Page 22: intro unix/linux 10

Managing Jobs

Suspending a job.

Identifying the most recent job.

Killing a particular job.

Page 23: intro unix/linux 10

Suspending a Job

The “stty –a” command is used to describe a list of CTRL

key settings used by the terminal and the shell for

communication.

The CTRL-Z key is used to suspend a job.

The suspended job does not use the system memory.

The “fg” command is used to bring the last suspended job

into the foreground.

Page 24: intro unix/linux 10

Suspending a Job

The “jobs” program lists all background and suspended jobs

and their status.

The “jobs” command is a shell built-in command.

A job’s output is divided into four columns – the job

number, the order, the status, and the command being

executed.

Page 25: intro unix/linux 10

Identifying the Most Recent Job

The “fg %+” is used to bring the most recently suspended

job to the foreground.

The “fg %-” is used to bring the second most recently

suspended job to the foreground.

Page 26: intro unix/linux 10

Identifying the Most Recent Job

The job number can also be used to get a job to the

foreground.

For example, “fg %2”, where %2 specifies the job with the

job number 2.

The job name can also be used to get a job to the

foreground.

Page 27: intro unix/linux 10

Killing a Job

The “kill %+” command is used to kill the most recent job in

the job list.

The job number can also be passed as an argument to kill that

particular job.

The job name can also be passed as an argument to kill a job.

Care should be taken while killing a job. We must not kill

wrong jobs.

Page 28: intro unix/linux 10

Exiting/Quitting When Jobs Have Been Stopped

Job control is a very useful method of managing processes.

UNIX job control provides a method of warning the users of

stopped or running background jobs when an attempt is

made to log out or exit a process.

It logs out without warning when we issue the same

command again, resulting in loss of unsaved data.

Page 29: intro unix/linux 10

Summary

Programs running in a system are executed by a process

that reads the appropriate code and accomplishes the

tasks.

All the processes have their own unique PID, the PID of their

parent, an owner, group, memory, code, input, output,

error, and their tty port.

Page 30: intro unix/linux 10

A command-line that consists of one process or a series of

processes connected by pipes is called a job.

The kill command terminates processes identified by either

their process ID or job number/job name.

Summary