Full Transcript

Process Management OPS102 Week 5 Class 1 Tiayyba Riaz/John Sellens June 4, 2024 Seneca Polytechnic Outline Monitoring Processes Process Control OPS102 W5C1 - Process Management 1/15 Monitoring Processes Process Management in Operating Systems Process management is an impo...

Process Management OPS102 Week 5 Class 1 Tiayyba Riaz/John Sellens June 4, 2024 Seneca Polytechnic Outline Monitoring Processes Process Control OPS102 W5C1 - Process Management 1/15 Monitoring Processes Process Management in Operating Systems Process management is an important concept in all operating systems. All programs that are executing on an operating system are referred to as processes. During the lifetime of a process, it uses many system resources like CPU and memory. The OS keeps track of the processes and of the system resources so that it can manage all the processes in the system fairly. There can be different scheduling strategies. We will look at process management for both Linux and Windows. OPS102 W5C1 - Process Management 2/15 Monitoring Processes in Linux For system administrators it is crucial to be able to monitor Which processes are running in the system The current state of the processes Resources these processes are taking Which user started which process A number of tools are available for terminal to monitor the processes like: "ps" offers a snapshot of processes "pstree" offers a tree view of process, branching from parent process to child process "top" offers a dynamic real time view of processes OPS102 W5C1 - Process Management 3/15 Linux: the "ps" Command By default it shows only processes/scripts running via terminal. Command line options can be used to display other processes as well. "ps x" – display all processes of current user "ps –e" – display all processes currently running "ps aux" – user-oriented variant, all processes "ps –u username" to display process of a user named username Sample output: OPS102 W5C1 - Process Management 4/15 Linux: the "ps" Command cont’d Columns description for ps command PID: Process ID TTY: The terminal that controls the process. In this case it is pts (pseudo terminal slave) Time: the number of hours, minutes and seconds the process has been running CMD: the command line, the process was called with Other options provide other information/columns OPS102 W5C1 - Process Management 5/15 Process States in Linux Processes in Linux can exist in four different states (R)unning: currently using the CPU (S)leeping: waiting in queue to use the CPU s(T)opped: stopped (but not terminated), either by user or other process (Z)ombie: terminated but is waiting for its parent process to retrieve its exit code OPS102 W5C1 - Process Management 6/15 Linux: the "pstree" Command Processes are always instantiated by other processes Your system starts with the "systemd" process Parent processes start child processes "pstree" shows a tree view of all current processes In the image below, the terminal emulator instantiated "bash" that instantiated "pstree" OPS102 W5C1 - Process Management 7/15 Linux: the "top" Command Provides a dynamic view of what’s going on Shows process listed according to CPU usage Shows memory usage and status OPS102 W5C1 - Process Management 8/15 Process Control Process Control in Linux There are two types of processes in Linux: Foreground: interactive, initialized by a user and controlled through terminal session. Background: non interactive, not connected to a terminal, don’t expect user input. User initiated processes run in foreground by default. Foreground processes take away the command line until process is finished. You can start a process in the background by appending "&" at the end of the command line. Example: "./script &" System related process usually run in the background and are called daemons. OPS102 W5C1 - Process Management 9/15 Starting a Process Once you run a command or program, it will start a process in the system. e.g. find -name "*.sh"./sum.sh It will be connected to the terminal and a user can send input to it. To start a process in the background (non-interactive), use the "&" symbol. e.g. firefox & You can send a process to the background (while also stopping it) by pressing Ctrl+Z and then the bq command OPS102 W5C1 - Process Management 10/15 Terminating (Signalling) a Process In order to terminate a process we can use the "kill" command. Syntax: "kill PID" (PID or %job) The kill command kills a single process at a time with the specified process id or job number. While the kill command is used to “kill” processes, its real purpose is to send signals to processes. Signals are intended to tell the process to (among other things) go away by gracefully terminating Many different signals are available Ctrl+Z sends the TSTP (terminal stop) signal OPS102 W5C1 - Process Management 11/15 Jobs – Foreground, Stopped, Background The shell starts processes and (with kill) signals processes And allows you to stop/re-start and foreground/background processes (jobs) Ctrl+Z stops the currently active foreground job and returns you to the shell prompt Easy way to pause, look something up, and resume your task The jobs command shows stopped and background processes bg moves a job to the background, fg moves to foreground Add a job number to affect a particular job e.g. bg %2 Consider: edit, save, stop editor, compile, run, fg back into editor, and repeat OPS102 W5C1 - Process Management 12/15 Some Available Signals OPS102 W5C1 - Process Management 13/15 Sending Signals to Processes You can send signals to process using the kill command: kill -SIGNAL PID "kill -15 PID" or "kill -TERM PID" sends a terminating signal to process PID "kill -9 PID" sends a KILL signal to terminate the process instantly If no option is specified kill command send a TERM signal OPS102 W5C1 - Process Management 14/15 Summary Process management is an important component of every operating system. As users, we should monitor the processes for better system performance. Next class: Windows Process Management OPS102 W5C1 - Process Management 15/15

Use Quizgecko on...
Browser
Browser