%% $Header: /cvsroot/lcdp/lpic/general-linux-1/slides/gl1.103.5.slides.tex,v 1.2 2003/05/30 05:06:17 waratah Exp $ \input{gl1.slide-header.tex} \slidesmag{3} %\overlaysfalse %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %============================================================================== \begin{slide} %ghr \listofslides \vfill \end{slide} %------------------------------------------------------------------------------ %----10->|-----20->|-----30->|-----40->|-----50->|-----60->|-----70->|-----80-> \begin{slide} %================================================================ \begin{center} \LARGE \textsf{-- General Linux 1 -- \\ Create, Monitor, and Kill Processes} \LARGE \textsf{[7] } \\[2mm] \large \textsf{(Linux Professional Institute Certification)}\\[1mm] \normalsize\end{center} \footnote{Copyright \copyright\ 2002 Geoffrey Robertson. Permission is granted to make and distribute verbatim copies or modified versions of this document provided that this copyright notice and this permission notice are preserved on all copies under the terms of the GNU General Public License as published by the Free Software Foundation---either version 2 of the License or (at your option) any later version.} \scriptsize \begin{verbatim} .~. /V\ by: geoffrey robertson // \\ geoffrey@zip.com.au @._.@ \end{verbatim} \tiny \begin{verbatim} $Id: gl1.103.5.slides.tex,v 1.2 2003/05/30 05:06:17 waratah Exp $ \end{verbatim} \normalsize \vfill \end{slide} %----------------------------------------------------------- %----10->|-----20->|-----30->|-----40->|-----50->|-----60->|-----70->|-----80-> %============================================================================== \begin{slide}{} %ghr %\Slidecontents \vfill \end{slide} %----------------------------------------------------------- %============================================================================== %============================================================================== \begin{slide} %ghr \slideheading{Overview} \slidesubheading{GNU \& Unix Commands} \begin{description} \item[1.103.1] Work on the command line \item[1.103.2] Process text streams using filters \item[1.103.3] Perform basic file management \item[1.103.4] Use streams, pipes, and redirects \item[1.103.5] {\bf \underline{Create, monitor, and kill processes}} \item[1.103.6] Modify process execution priorities \item[1.103.7] Search text files using regular expressions \end{description} \vfill \end{slide} %----------------------------------------------------------- %============================================================================== %============================================================================== \begin{slide} %ghr \Slideheading{Create, Monitor, and Kill Processes} \slidesubheading{Objective} Candidate should be able to manage processes. This includes knowing how to run jobs in the foreground and background, bring a job from the background to the foreground and vice versa, start a process that will run without being connected to a terminal and signal a program to continue running after logout. Tasks also include monitoring active processes, selecting and sorting processes for display, sending signals to processes, killing processes and identifying and killing X applications that did not terminate after the X session closed. \vfill \end{slide} %----------------------------------------------------------- %============================================================================== \begin{slide} %ghr \Slideheading{Create, Monitor, and Kill Processes} \slidesubheading{Key files, terms, and utilities} \begin{alltt} & bg fg jobs kill nohup ps top \end{alltt} \vfill \end{slide} %----------------------------------------------------------- %============================================================================== \begin{slide} %ghr \Slideheading{Create, Monitor, and Kill Processes} \slidesubheading{Resources of interest} \begin{alltt} \end{alltt} \vfill \end{slide} %----------------------------------------------------------- %============================================================================== %============================================================================== \begin{slide} \slideheading{Processes} \begin{itemize} \item A process is an executable loaded in memory. \item Linux is a multitasking operating system and so runs many processes concurrently. \begin{overlay}{1} \item INIT (PID 1) is the mother of all processes. \end{overlay} \begin{overlay}{2} \item Programs, daemons, shells and commands are all processes. \end{overlay} \begin{overlay}{3} \item The kernel automatically manages processes. \end{overlay} \begin{overlay}{4} \item Normally processes live, execute and die without intervention from users. \end{overlay} \end{itemize} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} \slidesubheading{Process Attributes and Concepts} The kernel starts the first process: \texttt{init} which has \textsf{PID 1} \begin{description} \begin{overlay}{1} \item[Lifetime:] Each process starts when it's command is executed, and lives till it dies or is killed. \end{overlay} \begin{overlay}{2} \item[Process ID (PID):] Every process has a unique number assigned to it when it is started. \end{overlay} \begin{overlay}{3} \item[User ID and Group ID:] Processes have the privileges associated with the user / group who started them. \end{overlay} \begin{overlay}{4} \item[Parent processes (PPID):] Shell processes are descendants of \textsf{init} and commands run from them are child processes. \end{overlay} \begin{overlay}{5} \item[Environment:] Each process inherits a set of \textit{environmental variables} from it's parent process. \end{overlay} \begin{overlay}{6} \item[Current Working Directory:] Each process starts with a default directory. \end{overlay} \end{description} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} \slidesubheading{Process Monitoring} Processes have to be monitored so as to check their health and use of system resources. \begin{itemize} \begin{overlay}{1} \item ps \small \begin{alltt} \$ ps aux |grep ssh root 866 0.0 0.3 2676 1268 ? S 07:56 0:00 /usr/sbin/sshd \end{alltt} \end{overlay} \begin{overlay}{2} \item pstree \small \begin{alltt} \$ pstree init-+-alarmd |-apmd |-kdeinit-+-autorun | |-kdeinit---emacs \end{alltt} \end{overlay} \begin{overlay}{3} \item top \small \begin{alltt} \$ top PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND 1792 geoffrey 11 0 8796 8796 7932 S 0.3 2.2 0:01 kdeinit 1590 root 14 0 57512 13M 2572 R 0.1 3.6 0:41 X 2857 geoffrey 14 0 1056 1056 836 R 0.1 0.2 0:01 top \end{alltt} \end{overlay} \end{itemize} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} \slidesubheading{Process Management} Normally the kernel automatically manages processes. However sometimes processes have to be started, stopped, restarted and killed. \begin{itemize} \begin{overlay}{1} \item Starting a process: \small \begin{alltt} \# /usr/sbin/httpd ps aux |grep httpd root 2987 0.0 0.4 4512 1584 ? /usr/sbin/httpd apache 3003 0.0 0.4 4656 1672 ? /usr/sbin/httpd \end{alltt} \end{overlay} \begin{overlay}{2} \item Occasionally processes die and have to be restarted. \end{overlay} \begin{overlay}{3} \item Processes may go berserk and have to be killed.\small \begin{alltt} \# kill -9 1234 \end{alltt} \end{overlay} \begin{overlay}{4} \item After configuration changes processes may have to be restarted so as to re-read their configuration files.\small \begin{alltt} \# service xinetd restart Stopping xinetd: [ OK ] Starting xinetd: [ OK ] \end{alltt} \end{overlay} \end{itemize} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slidesubheading{What is multitasking?} Multitasking is used to describe the situation where one processor (CPU) is used to perform multiple tasks concurrently. \begin{itemize} \overlay{1} \item Only one task or program is executing instructions on the CPU. \overlay{2} \item The CPU must be regularly switched between each program and others. \overlay{3} \item This process is known as a \textit{task switch}. \overlay{4} \item At each \textit{task switch} the Linux kernel must save the \textit{context} of the CPU. \overlay{5} \item The operating system uses the saved context when it switches back to the task the next time it gets some CPU time scheduled to it. \end{itemize} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slidesubheading{Task Scheduling} The total number of slices, when, how often and for how long the CPU is switched is determined by the multitasking algorithm and is handled by a software component within the kernel know as the \textit{task scheduler}. \begin{overlay}{1} There are three basic types of task scheduling: \begin{description} \overlay{2} \item[Nonpreemptive:] A task must relinquish the CPU before a task switch occurs. \overlay{3} \item[Preemptive:] The kernel takes away the CPU from a task without notice. \overlay{4} \item[Realtime:] Tasks are prioritised. High priority tasks must complete before a task switch. \end{description} \end{overlay} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slidesubheading{What is a Process?} The term process is a fundamental abstraction. \begin{itemize} \overlay{1} \item Two of the more traditional definitions of a process are: \begin{quote} ``A program in execution.'' \end{quote} \begin{quote} ``A single program running in its own virtual address space'' \end{quote} \overlay{2} \item In practice, a process is simply an executable that has been loaded into memory and is either running or ready to run on the system. \end{itemize} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slidesubheading{Process types} Processes under Linux fall into three basic categories: \begin{description} \overlay{1} \item[Interactive Process:] An interactive process is a process initiated from (and controlled by) a shell. Interactive processes may be in foreground or background. \\(Example: \texttt{ls, ls \&}) \overlay{2} \item[Batch Process:] A batch process is a process that is not associated with a terminal but is submitted to a queue to be executed sequentially. \\(Example \texttt{slocate} started by \texttt{cron}) \overlay{3} \item[Daemon Process:] A daemon process is a process that runs in the background until it's required. This kind of processes is usually initiated when Linux boots. \\(Example: \texttt{inetd}, \texttt{lpd}) \end{description} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slidesubheading{Elements associated with a process} For each process running on the system, the kernel needs to keep a list of resources used by that process. Some of these resources include: \begin{itemize} \overlay{1} \item tty association (\texttt{tty\_struct}) \overlay{2} \item file system (eg current directory \& open files) (\texttt{fs\_struct}, \texttt{files\_struct}) \overlay{3} \item memory allocation \texttt{(mm\_struct}) \overlay{4} \item Signals received (\texttt{signal\_struct}) \end{itemize} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slidesubheading{Process States} At any given point in time, a process is in one of 5 states: \begin{description} \overlay{1} \item[TASK\_RUNNING:] The process is either executing on the CPU or waiting to be executed. \overlay{2} \item[TASK\_INTERRUPTIBLE:] The process is sleeping until something becomes true. Raising a hardware interrupt, waiting for a system resource etc are examples of a condition that might wake the process up. If a signal is received by the process (eg KILL -HUP) the process will also be woken up. \overlay{3} \item[TASK\_UNINTERRUPTIBLE:] Like the previous state except that delivering a signal will not wake the process up. \overlay{4} \item[TASK\_STOPPED:] Process execution has stopped. A process enters this state after receiving a SIGSTOP signal. A debugger may use this to step through a program. \overlay{5} \item[TASK\_ZOMBIE:] Process execution has stopped but the kernel has not yet ?cleaned up? the resources allocated to the process. \end{description} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slidesubheading{The Process Family Tree} Every process (with the sole exception of the kernel), must be created by another process. The terms \textit{parent}, \textit{child} and \textit{sibling} (or sometimes \textit{father}, \textit{son} and \textit{brother} in a patriarchal sense) are used to describe the relationships between processes. As an example consider the following line executed from the bash prompt: \begin{alltt} [andy@Node4] andy]\$ ls \& df -h \& \end{alltt} The following relationships are true: \begin{itemize} \overlay{1} \item The \texttt{ls} and \texttt{df} processes are both siblings to each other. \overlay{2} \item The \texttt{bash} process (ie the shell) is the parent to both \texttt{ls} and \texttt{df}. \overlay{3} \item The \texttt{ls} process has \texttt{bash} as its parent. \overlay{4} \item The \texttt{df} process has \texttt{bash} as its parent. \end{itemize} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slidesubheading{The Kernel is at the Top of the Family Tree} \begin{itemize} \overlay{1} \item When Linux boots, the first thing it does is load the kernel into memory and start executing itself. \overlay{2} \item One of the first things it does once execution starts, is to spawn a process called init, which in turn spawns other processes. \overlay{3} \item In this sense, the kernel is at the top of the family tree, with only one child process called init. \overlay{4} \item Init in turn has many children and probably many grandchildren. \end{itemize} \begin{alltt} Kernel --> Init --> all other processes --> even more processes --> \end{alltt} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slidesubheading{Process IDs} In order for the kernel to keep track of all processes and their descendants, a process ID is assigned to every process running on the system. Process IDs are just numbers and run from 0 to 32767. The number 32767 is the largest signed integer available with a sixteen bit word size and is used to maintain backward compatibility with 16 bit architectures. There are two PIDs (process IDs) that are always the same: \begin{itemize} \item kernel PID is always 0 \item init PID is always 1 \end{itemize} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slidesubheading{Process IDs} Each time a new process is created, a new PID is allocated and is equal to the last PID issued plus one. Once the last PID is reached, the PID wraps back around to zero and the next available PID is used (note that 0 and 1 will never be available). This scheme is a little like the assignment of telephone numbers: When a telephone service is disconnected, rather than just assigning the old telephone number to a new subscriber, the old number remains out of use until all other numbers have been used up. This saves ``wrong numbers'' to the new subscriber from callers who have not yet realised that the old number is no longer connected to the person they were trying to reach. In a similar vein, the kernel does this to minimise ``wrong numbers'' from other processes who have not yet worked out that their intended process no longer exists. This is especially true for Interprocess Communication (IPC) which uses the PID to identify a target process. \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slideheading{Displaying Process Information} There are three utilities used to display the state of running processes: \begin{itemize} \item \texttt{ps} \item \texttt{pstree} \item \texttt{top} \end{itemize} \begin{itemize} \overlay{1} \item The ps command is used to display a ``snapshot'' of all processes running on the system at the time the \texttt{ps} command was executed. \overlay{2} \item \texttt{pstree} gives a tree view of the processes. \overlay{3} \item The \texttt{top} command is used to display a real-time display of all processes running on the system. Top can also be used in interactive mode to \texttt{kill} or \texttt{renice} (change priority) of a process. \end{itemize} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slidesubheading{Process Monitoring---\texttt{ps}} \begin{quote} \textit{usage:} \texttt{ps [options]} \end{quote} The \texttt{ps} command has a huge number of switches. The switches can be subdivided into two main groups: \begin{itemize} \item Process selection (which processes to display) \item Output control (how and what output should be displayed) \end{itemize} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide}%ghr \slidesubheading{\texttt{ps} options} \scriptsize \begin{alltt} \$ ps ? ERROR: Garbage option. ********* simple selection ********* ********* selection by list ********* -A all processes -C by command name -N negate selection -G by real group ID (supports names) -a all w/ tty except session leaders -U by real user ID (supports names) -d all except session leaders -g by session leader OR by group name -e all processes -p by process ID T all processes on this terminal -s processes in the sessions given a all w/ tty, including other users -t by tty g all, even group leaders! -u by effective user ID (supports names) r only running processes U processes for specified users x processes w/o controlling ttys t by tty *********** output format ********** *********** long options *********** -o,o user-defined -f full --Group --User --pid --cols -j,j job control s signal --group --user --sid --rows -O,O preloaded -o v virtual memory --cumulative --format --deselect -l,l long u user-oriented --sort --tty --forest --version X registers --heading --no-heading ********* misc options ********* -V,V show version L list format codes f ASCII art forest -m,m show threads S children in sum -y change -l format -n,N set namelist file c true command name n numeric WCHAN,UID -w,w wide output e show environment -H process heirarchy \end{alltt} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slidesubheading{\texttt{ps} options} The switches that need to be known for the purposes of LPIC are as follows: \begin{description} \item[{\bf\texttt{a}}] Display processes for all users \item[{\bf\texttt{txx}}] Display processes within controlling terminal \texttt{txx} \item[{\bf\texttt{u}}] Display user information for the process \item[{\bf\texttt{l}}] Display in long format with detailed information \item[{\bf\texttt{s}}] Display signal information \item[{\bf\texttt{m}}] Display memory information \item[{\bf\texttt{x}}] Display processes without a controlling terminal \item[{\bf\texttt{S}}] Display CPU time and page faults of child processes \item[{\bf\texttt{-C cmd}}] Search for instances of command \texttt{cmd.} \item[{\bf\texttt{-f}}] Forest mode shows process family trees. \item[{\bf\texttt{-w}}] Wide format \end{description} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slidesubheading{\texttt{ps} field names \& their meanings} \begin{description} \item[{\bf\texttt{USER}}] The user who started the process \item[{\bf\texttt{PID}}] The process ID \item[{\bf\texttt{\%CPU}}] Shows the cputime / realtime percentage. \item[{\bf\texttt{\%MEM}}] The fraction of RSS divided by the total size of RAM \item[{\bf\texttt{VSZ}}] Size of virtual memory used by the process \item[{\bf\texttt{RSS}}] Resident set size (Data \& Text segments only) in Kb \item[{\bf\texttt{TTY}}] The TTY associated with this process \item[{\bf\texttt{STAT}}] The current status (DRSTZW$<$ NL) (details next slide) \item[{\bf\texttt{TIME}}] CPU time in MINS:SECS \item[{\bf\texttt{COMMAND}}] The full command line used to start the process \end{description} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slidesubheading{\texttt{ps} Status Field} \small \begin{alltt} \$ ps aux USER PID \%CPU \%MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 1304 72 ? S Mar21 0:19 init \end{alltt} \normalsize \begin{description} \item[{\bf\texttt{D}}] uninterruptible sleep (usually IO) \item[{\bf\texttt{R}}] runnable (on run queue) \item[{\bf\texttt{S}}] sleeping \item[{\bf\texttt{T}}] traced or stopped \item[{\bf\texttt{Z}}] a defunct (``zombie'') process \item[{\bf\texttt{W}}] has no resident pages \item[{\bf\texttt{$<$}}] high-priority process \item[{\bf\texttt{N}}] low-priority task \item[{\bf\texttt{L}}] has pages locked into memory (for real-time and custom IO) \end{description} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Andrew Eager \slidesubheading{\texttt{ps} Status Field} \scriptsize \begin{alltt} \$ ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.2 1384 516 ? S 11:43 0:04 init [5] root 2 0.0 0.0 0 0 ? SW 11:43 0:00 [keventd] root 3 0.0 0.0 0 0 ? SW 11:43 0:00 [kapm-idled] root 5 0.0 0.0 0 0 ? SW 11:43 0:00 [kswapd] root 6 0.0 0.0 0 0 ? SW 11:43 0:00 [kreclaimd] root 7 0.0 0.0 0 0 ? SW 11:43 0:00 [bdflush] root 8 0.0 0.0 0 0 ? SW 11:43 0:00 [kupdated] root 9 0.0 0.0 0 0 ? SW< 11:43 0:00 [mdrecoveryd] root 103 0.0 0.0 0 0 ? SW 11:44 0:00 [kjournald] root 474 0.0 0.2 1444 620 ? S 11:44 0:00 syslogd -m 0 root 479 0.0 0.4 2080 1152 ? S 11:44 0:00 klogd -2 rpc 497 0.0 0.2 1632 708 ? S 11:44 0:00 portmap rpcuser 525 0.0 0.3 1624 796 ? S 11:44 0:00 rpc.statd ntp 735 0.0 0.8 2088 2080 ? SL 11:44 0:00 ntpd -U ntp root 759 0.0 0.3 5784 856 ? S 11:44 0:00 ypbind root 763 0.0 0.3 5784 856 ? S 11:44 0:00 ypbind ..... andy 1176 0.0 0.5 2620 1508 pts/0 S 11:46 0:00 bash root 1343 0.0 0.7 3000 1816 tty1 S 15:21 0:00 ssh node10 andy 1664 0.0 0.3 2824 924 pts/1 R 21:52 0:00 ps -aux \end{alltt} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %ghr \slidesubheading{Process Monitoring---\texttt{pstree}} \scriptsize \begin{alltt} \$ pstree init-+-anacron---run-parts---cfengine |-5*[apache-ssl] |-atd |-bash---startx---xinit-+-X | `-enlightenment-+-E-Clock.epplet | |-E-Cpu.epplet | |-Emix.epplet | |-Eterm---bash-+-abiword---AbiWord | | `-mozilla-bin---moz | |-Eterm---bash---bash | |-Eterm---bash | |-Eterm---bash---gv---gs | |-Eterm---bash---mutt | |-Eterm---bash---emacs-+-ispell | | `-xdvi---gs | |-Eterm---bash---pstree | `-Eterm---bash---man---pager |-cron |-gcache |-6*[getty] |-inetd---nmbd |-junkbuster \end{alltt} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %ghr \slidesubheading{\texttt{pstree} options} Three commonly used options for \texttt{pstree}: \begin{description} \overlay{1} \item[{\bf\texttt{-a}}] Show command line arguments. \begin{alltt} |-xfs -daemon |-xfstt --port 7101 --daemon --user nobody `-zope-z2 /usr/sbin/zope-z2 `-python /usr/sbin/zope-z2 \end{alltt} \overlay{2} \item[{\bf\texttt{-n}}] Sort processes with the same ancestor by PID \overlay{3} \item[{\bf\texttt{-p}}] Show PIDs. \begin{alltt} init(1)-+-anacron(27095)---run-parts(27755)---cfengine(27765) |-apache-ssl(27188) |-apache-ssl(27189) \end{alltt} \end{description} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Wayne Pitt \slidesubheading{Process Monitoring---\texttt{top}} The "top" command provides a continuously updated, real-time look at process activity, memory and swap file usage plus CPU activity. It also shows what processes are running and by whom. \begin{itemize} \item \begin{overlay}{1} Its primary use is as an administration and system information tool. It provides an extension to the functionality of the "ps" command. \end{overlay} \item \begin{overlay}{2} It makes it easy to find an errand process and "kill" that process. It also has an interactive interface whereby options can be passed while the command is actually running. All in all, a very useful tool. \end{overlay} \end{itemize} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Wayne Pitt \slidesubheading{\texttt{ top}} \small \begin{verbatim} 9:16am up 13 days, 8:05, 8 users, load average: 0.05, 0.05, 0.00 86 processes: 84 sleeping, 1 running, 1 zombie, 0 stopped CPU states: 2.3% user, 0.7% system, 0.0% nice, 96.8% idle Mem: 900236K av, 546472K used, 353764K free, 0K shrd, 37552K buff Swap: 329324K av, 34784K used, 294540K free 190764K cached PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND 10281 root 16 -10 97952 6452 1584 S < 0 3.9 0.7 56:57 X 12547 geoff 16 0 1728 1728 764 R 0 0.9 0.1 0:01 top 10284 geoff 12 0 3012 2568 1352 S 0 0.7 0.2 50:49 enlight 12173 geoff 10 0 9340 9340 3768 S 0 0.3 1.0 0:11 emacs 12543 geoff 9 0 3328 3328 2072 S 0 0.1 0.3 0:00 Eterm 1 root 9 0 116 72 52 S 0 0.0 0.0 0:19 init 2 root 9 0 0 0 0 SW 0 0.0 0.0 0:01 keventd \end{verbatim} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Wayne Pitt \slidesubheading{top's basic command line options} Note: dashes not required. \begin{description} \item[{\bf\texttt{-b}}] Batch mode. Useful for sending output from top to other programs or to a file. Output is plain text. \item[{\bf\texttt{-d}}] Delay between screen updates. (default 5 seconds) \item[{\bf\texttt{-i}}] Start top ignoring any idle or zombie processes. \item[{\bf\texttt{-p}}] Monitor only processes with given process id. (x20) \item[{\bf\texttt{-q}}] This causes top to refresh without any delay. \item[{\bf\texttt{}}] \item[{\bf\texttt{}}] \item[{\bf\texttt{}}] \item[{\bf\texttt{}}] \end{description} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Wayne Pitt \slidesubheading{\texttt{top}'s upper screen} \small \begin{verbatim} 9:16am up 13 days, 8:05, 8 users, load average: 0.05, 0.05, 0.00 86 processes: 84 sleeping, 1 running, 1 zombie, 0 stopped CPU states: 2.3% user, 0.7% system, 0.0% nice, 96.8% idle Mem: 900236K av, 546472K used, 353764K free, 0K shrd, 37552K buff Swap: 329324K av, 34784K used, 294540K free 190764K cached \end{verbatim} \begin{itemize} \overlay{1} \item The current system time: \overlay{2} \item The "up time" of the system: \overlay{3} \item How many users are logged in. \overlay{4} \item The "load average" : the average number of processes ready to run over the last 1,5 and 15 minutes \overlay{5} \item "CPU States" shows the percentage of CPU time spent in usermode, system mode and at idle. \overlay{6} \item "MEM" shows a complete set of statistics on current memory usage. \overlay{7} \item "SWAP" gives us the same details as "MEM" but for the swap space. \end{itemize} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Wayne Pitt \slidesubheading{top's lower screen} \small \begin{verbatim} PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND 10281 root 16 -10 97952 6452 1584 S < 0 3.9 0.7 56:57 X 12547 geoff 16 0 1728 1728 764 R 0 0.9 0.1 0:01 top \end{verbatim} \begin{description} \overlay{1} \item[PID] The process ID of each task. \overlay{2} \item[USER] The user name of the task's owner. \overlay{3} \item[PRI] The priority of the task. \overlay{4} \item[NI] The nice value of the task. Negative nice values are higher priority. \overlay{5} \item[SIZE] The size of the task's code plus data plus stack space, in kilobytes, is shown here. \overlay{6} \item[RSS] The total amount of physical memory used by the task,in kilobytes, is shown here. For ELF processes used library pages are counted here, for a.out processes not. \overlay{7} \item[SHARE] The amount of shared memory used by the task is shown in this column. \end{description} \vfill ctd\ldots \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Wayne Pitt \slidesubheading{top's lower screen} \small \begin{verbatim} PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND 10281 root 16 -10 97952 6452 1584 S < 0 3.9 0.7 56:57 X 12547 geoff 16 0 1728 1728 764 R 0 0.9 0.1 0:01 top \end{verbatim} \begin{description} \overlay{1} \item[STAT] The state of the task is shown here. The state is either \begin{description} \item[S] sleeping \item[D] uninterruptible sleep \item[R] running \item[Z] zombies \item[T] stopped or trace \end{description} These states are modified by trailing $<$ for a process with negative nice value, N for a process with positive nice value, W for a swapped out process (this does not work correctly for kernel processes). \overlay{2} \item[\%CPU] The task's share of the CPU time since the last screen update, expressed as a percentage of total CPU time per processor.\ \overlay{3} \item[\%MEM] The task's share of the physical memory. \end{description} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %ghr \slidesubheading{\texttt{top}: selected interactive commands} \begin{description} \item[\textasciicircum L] Redraw the screen \overlay{1} \item[f$\mid$F] Add and remove fields \overlay{2} \item[h$\mid$?] Displays a help screen \overlay{3} \item[S] Toggle cumulative mode \overlay{4} \item[I] Toggle between Irix and Solaris views (SMP-only) \overlay{5} \item[k] Kill a task (with any signal) \overlay{6} \item[r] Renice a task \overlay{7} \item[T] Sort by time / cumulative time \overlay{8} \item[s] Set the delay in seconds between updates \overlay{9} \item[q] Quit \end{description} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Wayne Pitt \slidesubheading{\texttt{top}'s interactive commands} \begin{description} \item[space] Update display \item[\textasciicircum L] Redraw the screen \item[f$\mid$F] Add and remove fields \item[o$\mid$O] Change order of displayed fields \item[h$\mid$?] Displays a help screen \item[S] Toggle cumulative mode \item[i] Toggle display of idle processes \item[I] Toggle between Irix and Solaris views (SMP-only) \item[c] Toggle display of command name/line \item[l] Toggle display of load average \item[m] Toggle display of memory information \item[t] Toggle display of summary information \item[k] Kill a task (with any signal) \item[r] Renice a task \item[N] Sort by pid (Numerically) \item[A] Sort by age \item[P] Sort by CPU usage \item[M] Sort by resident memory usage \item[T] Sort by time / cumulative time \item[u] Show only a specific user \item[n$\mid$\#] Set the number of process to show \item[s] Set the delay in seconds between updates \item[W] Write configuration file ~/.toprc \item[q] Quit \end{description} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Wayne Pitt \slidesubheading{\texttt{\~{}\slash .toprc}} \begin{alltt} \$ cat toprc \(\hookleftarrow\) AbcDgHIjklMnoTP|qrsuzyV\{EFWx 2 \end{alltt} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} \slidesubheading{Killing Processes} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Alex J \slidesubheading{Job Control} There are three commands and a pretzel used for job control. \begin{itemize} \item \texttt{jobs} \item \texttt{fg} \item \texttt{bg} \item \texttt{\&} \end{itemize} \begin{overlay}{1} They are bash built-ins: \begin{alltt} \$ type jobs fg bg \(\hookleftarrow\) jobs is a shell builtin fg is a shell builtin bg is a shell builtin \end{alltt} For more information, see the Job Control section of man bash. \end{overlay} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Alex J \slidesubheading{\texttt{\&}--- Direct the shell to execute a command in the background.} Example: \begin{alltt} \$ xeyes \(\hookleftarrow\) \end{alltt} Notice the \texttt{xeyes} process is started in the foreground and you have no prompt. The user is locked out of further interaction with the shell until a process is stopped, terminated or completed. Now start the xeyes process in the background. \begin{alltt} \$ xeyes & \(\hookleftarrow\) [1] 1650 \$ \end{alltt} Two numbers are listed and the prompt is now also displayed waiting for another command. \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Alex J \slidesubheading{Job Control} \begin{alltt} \$ xeyes & \(\hookleftarrow\) [1] 1650 \$ \end{alltt} \begin{itemize} \overlay{1} \item The [1] is the programs job id, a unique number for the shell starting from 1. \overlay{2} \item The 1650 is the process id (pid), which identifies the process across the entire system. \overlay{3} \item Either of these numbers can be used to interact with the program through bash. \end{itemize} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Alex J \slidesubheading{Background Processing} The best candidates for background processing are programs that do not require user input, as these programs will keep on waiting until input is provided. Programs that send their results to standard output (The screen), will do so even if running in the background. If the user is performing another operation, the results may be difficult to interpret. The output from these processes can be redirected to a file. \begin{alltt} \$ wc bigfile > bigfile.wc & \(\hookleftarrow\) [1] 1654 \$ \end{alltt} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Alex J \slidesubheading{The \texttt{jobs} command} \begin{description} \overlay{1} \item [\texttt{\$ jobs \(\hookleftarrow\)}]:\\ Lists all commands stopped, or running in the background. \overlay{2} \item [Options]:\\ \texttt{-l} List pid \overlay{3} \item [Example]:\\ Start some processes in the background and suspend a foreground process. \begin{alltt} \$ jobs \(\hookleftarrow\) [1]+ Stopped less job_control.txt [2]- Running xeyes & \$ \end{alltt} \end{description} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Alex J \slidesubheading{The \texttt{fg} command} \begin{description} \item [\texttt{\$ fg \(\hookleftarrow\)}]:\\ Shell built-in used to force a suspended or background process to continue running in the foreground. \overlay{1} \item [Example]: \begin{itemize} \item Use the 'jobs' command to find job id. \begin{alltt} \$ jobs \(\hookleftarrow\) [1]+ Stopped less job_control.txt [2]- Running xeyes & \$ \end{alltt} \overlay{2} \item Use \texttt{fg} to bring xeyes to foreground. \begin{alltt} \$ fg 2 \(\hookleftarrow\) xeyes \end{alltt} \overlay{3} \item A \texttt{\%} used with the job id is equivalent to \texttt{fg 2}. \begin{alltt} \$ \%2 \(\hookleftarrow\) xeyes \end{alltt} \end{itemize} \end{description} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} %Alex J \slidesubheading{The \texttt{fg} command} A job can also be referred to by a string that uniquely identifies the beginning of the command line used to start a job. A '\%' can also be used with a unique string. \begin{alltt} \$ fg x \(\hookleftarrow\) xeyes \end{alltt} or \begin{alltt} \$ \%x \(\hookleftarrow\) xeyes \end{alltt} If \texttt{fg} is issued without any argument, the job with the '+' in the job list is brought to the foreground. \begin{alltt} \$ fg \(\hookleftarrow\) xeyes \end{alltt} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide} \slidesubheading{The \texttt{bg} command} \begin{description} \item [\texttt{\$ bg \(\hookleftarrow\)}]:\\ Used to force a suspended process to continue running in the background. \overlay{1} \item [Example]:\\ Use the 'jobs' command to find job id. \begin{alltt} \$ jobs \(\hookleftarrow\) [1]- Stopped find -name myfile >myfile.found (wd: /) [2]+ Stopped less job_control.txt [3] Running xeyes & \$ \end{alltt} \end{description} Job 1 shows the 'find' command was started in the foreground and then suspended.To start 'find' in the background, use the 'bg' command or '\%'. \begin{description} \overlay{2} \item [Example]: \begin{alltt} \$ bg 1 \(\hookleftarrow\) {\rm or} \$ bg f \(\hookleftarrow\) {\rm or} \$ \%1 \& \(\hookleftarrow\) {\rm or} \$ \%f \& \(\hookleftarrow\) \end{alltt} \end{description} \normalsize \vfill \end{slide} %--------------------------------------- %============================================================================== \begin{slide}{} %ghr \heading{The End} \Slidecontents \vfill \end{slide} %----------------------------------------------------------- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \end{document} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %============================================================================== %============================================================================== \begin{slide}{} \slideheading{} \vfill \end{slide} %----------------------------------------------------------- ============================================================================= \begin{slide}{} \end{slide} %------------------------------------------------------------------