Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott...

26
Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University

Transcript of Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott...

Page 1: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Managing Processes

CSCI N321 – System and Network Administration

Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University

Page 2: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Section Overview

UNIX Processes

Running programs

Monitoring processes

Killing processes

Page 3: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

References

CQU 85321 System Administration Course

Chapter 5

Page 4: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Programs & Processes

Program – file which can be run Binary executables Shell scripts

Process – A running program Loaded in physical memory Stored in virtual memory (swap)

Page 5: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Virtual Memory

Extends amount of physical memoryUNIX Size of swap = amount of usable memory Physical memory (RAM) mirrored in swap

Linux: Memory = swap + RAMSwapping Moving pages to and from memory Page – block (unit) of RAM

Page 6: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Swap AllocationBSD UNIX:

RAM:

Swap:

AT&T SVR4/Linux:

RAM:

Swap:

Which works better when?

Windows: C:\pagefile.sys (Grows as needed)

Page 7: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Windows pagefile.sys Settings

Page 8: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

WaitWait

DoneDone

Process Lifecycle

NewNew ReadyReadyAdmittedAdmitted

SchedulerSchedulerDispatchesDispatches

InterruptInterrupt

RunRun

ExitExit

I/O I/O RequestRequestI/O CompletedI/O Completed

Page 9: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Process Components

Sleeping Stopped

Address space mapStatus

OwnerBlocked Signals PriorityResources used

Running Runable

Zombie

Page 10: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Process Ownership

Real User (User starting the process) UID: User ID Number GID: Group ID Number

Effective User (Permissions for process) EUID: Effective User ID Number EGID: Effective Group ID Number

Page 11: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Process Lifecycle

Parent process “forks” a childProcess identifiers PID: Process ID Number PPID: Parent Process ID Number

Child finishes Sends status message to parent Zombie – waits for parent

acknowledgment Orphan – init (PID 1) becomes parent

Page 12: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Running a command

Type in the command nameShell searched for the commandIf found, shell “forks” the commandHow is the command found? PATH environment variable which – Displays full path to command Beware of “.” in your PATH

Page 13: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Background Jobs

Foreground process Returns control to shell after it

finished Most common usage

Background process Returns control to shell immediately “&” typed after command name Runs concurrently

Page 14: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Daemons

Special programs which performs a some task without interventionStarted in the background (often at system startup)

Name of most ends in ‘d’

“Daemon” is actually a much older form of “demon”; daemons have no particular bias towards good or evil, but rather serve to help define a person's character or personality.

~Evi Nemeth

Page 15: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

fg, bg, & jobs

Can switch between modesSend signal to stop a processCommands fg – Run process in foreground bg – Run process in background jobs – List shell child processes

Page 16: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Signals

Used to communicate with processesTerminal signals <Ctrl><c> - Terminate process <Ctrl><z> - Stop (suspend) process

kill [-signal] pid Sends signal to process PID Default is to terminate the process

Page 17: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Common Signals

## NameName DescriptionDescription

1 HUP Hangup

2 INT Interrupt

3 QUIT Quit

9 KILL KILL

15 TERM Software Termination

STOP Stop

Page 18: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Process Priority

How much CPU time granted relative to other processesnice – Sets the priority value at startrenice – Changes priorityRangesSystemSystem RangeRange

Solaris 0 to 39

RedHat -20 to 20

Page 19: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

System Load

Average number of “Runnable” processesMeasure of how busy the system isPerformance deteriorates at loads of 6+Good for creating a baselineuptime – Load average (5, 10, 15 minutes)

Page 20: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Monitoring Processes (Linux)

ps BSD – Sorts by %CPU Usage SVR4 – Sorts by PID

top Full terminal screen display Sortable Can kill and renice processes

Page 21: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Information from ps

PID

USER

PRI/NI - Priority/Nice levelRSS/SIZE - Resident/Total Memory usedSTAT - Process State%CPU/%MEM - % of System CPU/MemoryTIME - CPU time usedCommand

Page 22: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

/proc Filesystem

Pseudo filesystem Interface to memory-related kernel data structuresEach PID has it’s own directory cwd – Symlink to current working directory exe – Symlink to program cmdline – command line options environ – command line environment stat – process status

Page 23: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Monitoring Processes (Windows)

Task Manager Graphical viewer Can also sort or kill processes

tasklist Command line Viewer Can view associated dll files

wmic process [options] Can view, start, and kill processes Remote connection capabilities

Page 24: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

SysInternals - Process Tools

Command Line tools Pslist – display running processes Pskill – Kill processes by name or PID Psexec – Run programs remotely

GUI Tools Procmon – Detailed process info RAMMap – View RAM usage VMMap – View Virtual Memory usage

Page 25: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Runaway Processes

Can eat up your resourcesLists users and PIDs accessing a resource fuser lsof

Kill the process and clean up

Page 26: Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.

Elevating Access

Principle of Least Privilege su [-] <user> - “Switch user” Requires user password if not run as root ‘-’ runs a subshell owned by user

Microsoft runas (Automatic Popup Win7)Sudo – Run programs as superuser /etc/sudoers – who can run what visudo – Editor for /etc/sudoers sudo – Used to run commands as root Windows version available