12
Junior Level Linux Certification

101 3.5 create, monitor and kill processes

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: 101 3.5 create, monitor and kill processes

Junior Level Linux Certification

Page 2: 101 3.5 create, monitor and kill processes

Exam Objectives

Key Knowledge Areas

Run jobs in the foreground and background. Signal a program to continue running after logout. Monitor active processes. Select and sort processes for display. Send signals to processes.

Objective 3: GNU and Unix Commands

Create, monitor and kill processes Weight: 4

Terms and Utilities

& bg fg jobs kill nohup ps top free uptime killall

2

Page 3: 101 3.5 create, monitor and kill processes

Create, monitor and kill processes

Job control - Ability to selectively suspend execution of processes and continue their execution later.

A job is a process or a pipeline of processes that were started by the shell.

Job control

3

job which receives keyboard input is called the foreground job.

•When a foreground process is running, it receives keyboard input and signals.•Processes started are run in foreground by default and continue until they exit.

To run a process in background – input command followed by special character &

•Processes running in the background may still send output to the terminal.•They do not receive keyboard input unless they are brought to the foreground.

When bash starts a background job, it prints a line with: - job number and - process ID of last process in pipeline

Page 4: 101 3.5 create, monitor and kill processes

Create, monitor and kill processes

Job control - Ability to selectively suspend execution of processes and continue their execution later.

A job is a process or a pipeline of processes that were started by the shell.

Job control

4

job which receives keyboard input is called the foreground job.

•When a foreground process is running, it receives keyboard input and signals.•Processes started are run in foreground by default and continue until they exit.

To run a process in background – input command followed by special character &

•Processes running in the background may still send output to the terminal.•They do not receive keyboard input unless they are brought to the foreground.

When bash starts a background job, it prints a line with: - job number and - process ID of last process in pipeline

Page 5: 101 3.5 create, monitor and kill processes

Create, monitor and kill processes

command jobs displays current list of jobs either running or stopped.

jobs

5

foo:~ $ dd if=/dev/zero of=/dev/null bs=1 &[1] 1181foo:~ $ cat /dev/urandom | grep hello &[2] 1183foo:~ $ jobs[1]- Running dd if=/dev/zero of=/dev/null bs=1 &[2]+ Running cat /dev/urandom | grep hello &

Ex:

Page 6: 101 3.5 create, monitor and kill processes

Create, monitor and kill processes

Control jobs

6

key sequences entered to foreground processes:Key Signal Meaning Usage

Ctrl+C SIGINT Interrupt Interrupt the program running in the foregroundCtrl+Z SIGSTOP Suspend Suspend the program running in the foreground

cmds entered to control background processes.Command Meaning Usage

fg foreground Run the background job in the foreground. If it has suspended, restart it.bg background Restart a suspended job.

fg makes most recently executed job a foreground job. You can specify a specific job number. (Ex. fg 2 will make job 2 run in the foreground)

bg makes most recently executed job continue to run in background.You can make a specific job run in the background by specifying a job number (Ex. bg 2)

Page 7: 101 3.5 create, monitor and kill processes

Create, monitor and kill processes

Control jobs

7

kill command kill job based on job number (instead of PID) using percentage sign to specify the job number

foo:~ $ jobs[1]- Running dd if=/dev/zero of=/dev/null bs=1 &[2]+ Running cat /dev/urandom | grep hello &foo:~ $ kill %1foo:~ $[1]- Terminated dd if=/dev/zero of=/dev/null bs=1foo:~ $ jobs[2]+ Running cat /dev/urandom | grep hello &foo:~ $ kill %2foo:~ $[2]+ Terminated cat /dev/urandom | grep hello

Ex:

Page 8: 101 3.5 create, monitor and kill processes

Create, monitor and kill processes

Disconnected processes

8

commands nohup and setsid - used to run processes disconnected from terminal that started them.

nohup sets the signal mask for the process it starts to ignore the SIGHUP signal.SIGHUP signal is sent to each process when the shell exits. - happens when you exit a session on console, or via network connection.

•nohup writes the output to a file - nohup.out•nohup is generally used - When you know that the process you are going to run should continue to run after your session ends.

Page 9: 101 3.5 create, monitor and kill processes

Create, monitor and kill processes

Monitoring processes

9

ps – process status

options supported by ps are somewhat complex.GNU version supports: Unix98 options (letters); BSD options (dash); GNU options (two dashes).To ... Unix98 BSD- Show all processes ps -ax ps -A ps -e- Show full info ps -u (user format) ps -f (full listing)

- Show full info for all processes ps -uax ps -ef ps -Af

foo:~ $ ps -fUID PID PPID C STIME TTY TIME CMDgeorgem 987 612 0 20:32 pts/2 00:00:00 /bin/bashgeorgem 3398 987 0 21:11 pts/2 00:00:00 ps -ffoo:~ $ ps uUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDgeorgem 987 0.0 1.7 4676 2040 pts/2 S 20:32 0:00 /bin/bashgeorgem 3399 0.0 0.5 2524 696 pts/2 R 21:11 0:00 ps u

Ex:

ps -w – display in wide formatps -f – display in forest of processes, similar to output of pstree.

Page 10: 101 3.5 create, monitor and kill processes

Create, monitor and kill processes

Monitoring processes

10

top – displays processes that use up the most CPU or memory.

Ex:

Page 11: 101 3.5 create, monitor and kill processes

Create, monitor and kill processes

Signals

11

Processes in Linux do not communicate with each other directly, but send each other signalsvia kernel.

most common signal sent is SIGTERM, means Terminate, unless you know what to do

signal(7) man page.

Ex:

http://linux.about.com/od/commands/l/blcmdl7_signal.htm

Page 12: 101 3.5 create, monitor and kill processes

Fim de sessão

12