Management and

Miroslav Biňas (c) 2010 - 2013

What is a Process? I.

●program - an organized list of instructions that, when executed, causes the computer to behave in a predetermined manner ●process - an instance of running program ○every process has unique ID (PID) ○PID can be used to modify process priority or to stop it ○child process and parent process

What is a Process? II.

●thread - a part of program that can execute independently of other parts Process Life Cycle

Process States I.

●ready - the process is competing for the processor or could be executed, but another process is currently being executed ●execution - the process is active or running or being executed by processor ●suspend - the process is waiting for an external event

Process States II.

●stopped -the process has been suspended by an external process ●zombie - the process has finished executed, but it is still references in the system Viewing Processes I.

●pstree - display tree of processes ○gives good illustration of parent and child process hierarchy ○options ■-p - display PIDs ■-h - highlight current processes and its ancestors (users processes)

Viewing Processes II.

●ps - report a snapshot of the current processes ○users have a set of popular combinations, such as: ps aux - all procs on the system ps T - procs run under the current terminal by the user ps ux - all procs run by user ●several kinds of options: UNIX, BSD and GNU long options

Viewing Processes III.

●-a - show all processes for the current user linked to a tty (except the session leader) ●-e or -A show all processes ●-f gives the PPID (Parent Process ID) and the STIME (Start Time) ●-l (similar to -f) long list ●a show all processes linked to a tty, including other users ●x show all processes without a controlling tty as well Viewing Processes IV.

●top - display Linux tasks ○provides dynamic real-time view ■refresh every 5s (default) ○press h for help while running ●htop - interactive process viewersimilar to top ○task related to processes can be done without entering their PID's

Viewing Processes V.

●system load - a measure of the amount of work that a computer system performs ●load average - the average system load over a period of time ○appears in the form of three numbers, which represents load during last 1, 5 and 15 minute periods ○uptime command

Signals I.

- special message, which is sent to a running process ○64 signals available (to get list of all signals, type -l) Signals II.

●most common signals: ○1 or SIGHUP hangup or disconnect the process ○2 or SIGINT same as ^C interrupt ○3 or SIGQUIT quit ○9 or SIGKILL kill the process through a kernel call ○15 or SIGTERM terminate a process 'nicely', the default signal

Tools to Send Signals

●kill - send a signal to a process by it's PID ○syntax: kill SIGNAL PID ●killall - kill process by the name of the process ○syntax: killall SIGNAL CMD ●process can choose to catch or not to catch signal except SIGKILL - handled by kernel

Process Priority with nice

●each process has niceness value ○affects process scheduling ●nice runs program with modified scheduling priority ○range from -20 (most favorable) to 19 (least favorable) ●program inherits its nice value from its parent (usually 0) ○prevents low priority processes from spawning high priority children Alter Running Process with renice ●syntax: renice -n PRIORITY -p PID ●users can only increase their niceness of process ○only root can decrease niceness

Job Control

●abililty to selectively stop (suspend) the execution of processes and continue (resume) later via interactive interface - shell ○keeps table of executing jobs ○list with jobs command ●running command in background $ xclock -update 1 & [1] 2564

Controling Jobs

●program can be stopped (suspend) by ^Z ○continue in background with bg ●to bring job to foreground, use fg ○if several jobs are in bg, brings to fg only last one ○to fg specific job, use fg %JOBID syntax ●to kill specific job, use kill SIGNAL %JOBID syntax Execute Commands after Exit ●nohup - run a command immune to hangups, with output to a non-tty ●syntax: nohup COMMAND & ●often used with nice to lower priority nohup nice COMMAND &

Screen

●"Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells)." ●great for remote access ●several excellent features ○multiple windows, logging, sessions ●to run screen, type screen

Using Screen

●meta key ^A in combination with: ○c - create new window ○k - kill current window ○n - next window ○p - previous window ○a - last window ○X - where X is number of window ○D - detach session ○H - creates running session log ○x - locks the screen ○? - help Advanced Screen

●to retach screen session run: $ screen -DRS default ●configuration in .screenrc ●byobu

/proc Directory

●virtual filesystem ●two types of content ○ numbered directories ○ system information files ●several commands provides info from this directory

/proc: Numbered Directories ●number represents the process id ●files inside directory are related with the process ○ cmd line, environment variables, limits, ... ○ links to process working directory (cwd), process executable (exe), ... /proc: System Information Files ●contains information about overall system (cpuinfo, meminfo, loadavg, partitions, version, ...) ●some commands provides info from /proc ○ free -> reads info from /proc/meminfo ●to get more info, do $ man 5 FILENAME

Questions?