What is a Process in an Operating System?

Visual Computer Science
29 Aug 202107:00

Summary

TLDRThis lecture delves into the concept of a process in operating systems, explaining its role as a unit of work and its lifecycle through various states such as new, ready, running, waiting, and terminated. It highlights the importance of the operating system in managing processes, the function of the scheduler in process execution, and the concept of preemptive multitasking with time slices for CPU usage. The lecture also touches on the trade-offs between responsiveness and performance in different system types and introduces the process control block that stores essential information about each process.

Takeaways

  • 💻 The operating system (OS) acts as the first software layer on top of the hardware, managing applications and system resources.
  • 🔧 The OS is responsible for task management, which includes executing programs on the CPU, either by user initiation or the OS itself.
  • 📝 A program must be compiled into an executable format like a .jar or .exe file before it can be run on the CPU.
  • 🚀 When an executable file is launched, the OS creates a process object in memory, which it manages throughout its lifecycle.
  • 🔑 A process is defined as an instance of a program loaded into memory, representing a unit of work in the OS.
  • 🌀 A process has various states, starting with 'new', transitioning to 'ready', and then to 'running', 'waiting', and finally 'terminated'.
  • ⏱️ The scheduler is a dedicated OS component that selects processes to run on the CPU, implementing preemption to manage CPU time among processes.
  • 🔄 Preemptive multitasking allows the CPU to execute parts of different processes in intervals, preventing any single process from monopolizing the CPU.
  • 📊 The number of CPU cores affects the system's throughput; more cores allow more processes to run in parallel.
  • 🕒 The time limit for CPU usage by a process is known as a time slice, which is crucial for balancing process execution and system responsiveness.
  • 🔄 Context switching is the process of changing the currently running process on the CPU, which can impact performance if frequent.
  • 🗂️ The process control block (PCB) stores vital information about a process, including its state, ID, privileges, scheduling info, and memory allocation.

Q & A

  • What is the role of the operating system in a computer's architecture?

    -The operating system acts as the first software layer on top of the hardware, managing the CPU, memory, and devices. It is responsible for task management, security, performance, and other responsibilities, serving as an interface between the hardware and the applications layer.

  • What is a process in the context of an operating system?

    -A process is an instance of a program loaded into memory or a unit of work in an operating system. It is an object stored in memory that contains information about the execution of a particular program and is managed by the operating system.

  • How does a program become executable on the CPU?

    -A program, which is initially a text file with instructions, needs to be compiled into an executable binary file, such as a .jar or .exe file, which can then be launched by the operating system to create a process object in memory.

  • What is the initial state of a process when it is created?

    -When a process is created, its initial state is 'new'. It then transitions to the 'ready' state when it is prepared to be run on the CPU.

  • What is the role of the scheduler in an operating system?

    -The scheduler is a dedicated component of the operating system responsible for selecting processes in the ready state and placing them onto the CPU for execution, based on a well-defined algorithm.

  • What is preemption in the context of process execution?

    -Preemption is the behavior where the operating system moves a running process back to the ready state to allow other processes to use the CPU. This ensures that the CPU is shared among multiple processes.

  • What is the purpose of the waiting state in a process's lifecycle?

    -The waiting state is when a process needs to wait for some external resources, such as data received over the network. During this state, the process is not executing on the CPU but is waiting for the required resources to become available.

  • How does having multiple CPU cores affect the system's throughput?

    -Having multiple CPU cores allows the system to handle multiple processes in parallel, effectively tripling the throughput if there are three cores, as each core can execute a process simultaneously.

  • What is preemptive multitasking and why is it important?

    -Preemptive multitasking is a mechanism where the CPU executes small parts of different processes at different times, rather than running a single process for a long duration. This ensures that the system remains responsive and can handle multiple tasks concurrently.

  • What is a time slice in the context of process execution?

    -A time slice is the specific time limit during which a process is allowed to use the CPU. This value, typically around 100 milliseconds on Linux, is dynamically adjusted by the operating system to manage the execution of processes.

  • What is a context switch and why is it significant?

    -A context switch is the operation of changing the process that is currently running on the CPU with another process. It is significant because it allows for multitasking and efficient CPU usage, but it can also impact performance due to the overhead involved in saving and loading the state of processes.

  • What information is typically stored in a process control block?

    -A process control block contains the current state of the process, a unique ID, privileges specifying resource access, a pointer to the next instruction, CPU register data, scheduling information like priority, virtual memory allocation, a pointer to the parent process, and information about file descriptors used by the process.

Outlines

00:00

🖥️ Understanding Processes and Task Management in Operating Systems

This paragraph introduces the concept of a process in an operating system, explaining its role within the computer's architecture. It describes the operating system as a complex component that manages tasks, which are programs to be executed on the CPU. The process lifecycle is detailed, starting from the creation of an executable binary file from a program, through the various states a process goes through, such as new, ready, running, waiting, and terminated. The paragraph also explains the role of the scheduler in managing process execution and the concept of preemption, which allows the operating system to manage CPU time among multiple processes. The example of a single CPU core handling multiple processes illustrates the process lifecycle and the impact of having multiple CPU cores on system throughput.

05:02

🕒 Preemptive Multitasking and Process Scheduling

This paragraph delves into the specifics of preemptive multitasking, explaining how it prevents system unresponsiveness by assigning a time limit, known as a time slice, for each process's CPU usage. It contrasts the needs of user-oriented operating systems, which prioritize responsiveness, with server-side systems that favor performance and may allow longer-running processes. The paragraph also discusses the importance of the type of workload in determining the appropriate level of multitasking. It introduces the concept of a context switch, which is the operation of changing the process being run on the CPU, and hints at potential performance issues related to this operation. Lastly, it outlines the information stored in a process control block, which includes the process's state, ID, privileges, pointers, scheduling information, virtual memory allocation, and file descriptors, noting that the exact content may vary by operating system.

Mindmap

Keywords

💡Process

A 'process' in the context of an operating system refers to an instance of a program loaded into memory. It is a fundamental concept in the video, as it represents a unit of work that the operating system manages. The process is not an active entity by itself but contains information about the execution of a program. For example, the script mentions that when a binary file is launched for execution, the operating system creates a process object in memory, which is then managed by the OS.

💡Operating System

The 'operating system' is the first software layer on top of the hardware in a computer's conceptual architecture. It is responsible for managing the hardware resources and providing services to applications. The script emphasizes the operating system's role in task management, creating process objects, and scheduling their execution on the CPU. It is a complex component with various responsibilities, including security and performance.

💡CPU

The 'CPU', or Central Processing Unit, is the hardware component at the bottom of the computer's architecture that executes program instructions. The script discusses how processes are programs that need to be executed on the CPU, which is done by compiling a text file of instructions into an executable binary file. The CPU's role is central to the process lifecycle, as it is where the processes are actually run.

💡Task Management

'Task management' is highlighted as one of the most important responsibilities of the operating system. In the script, it refers to the management of processes, which are programs to be executed on the CPU. This includes creating process objects, scheduling their execution, and handling their various states, such as ready, running, waiting, and terminated.

💡Executable

An 'executable' is a binary file that contains compiled program instructions ready to be run on the CPU. The script explains that a program, initially a text file, must be compiled into an executable format like a .jar or .exe file before it can be executed. This transformation is necessary for the operating system to create a process object from the program.

💡Scheduler

The 'scheduler' is a dedicated component of the operating system responsible for selecting processes from the ready state and placing them onto the CPU for execution. The script describes how the scheduler operates in a single CPU core scenario, picking one process at a time based on a defined algorithm, and how it manages process execution in a multi-core environment to increase system throughput.

💡Process State

A 'process state' refers to the condition of a process at any given time, such as new, ready, running, waiting, or terminated. The script explains the lifecycle of a process, detailing how it transitions between these states from creation to completion. For instance, a process initially in the new state moves to the ready state, then possibly to running, waiting, and finally to terminated.

💡Preemption

'Preemption' is the behavior where the operating system moves a running process back to the ready state to allow other processes to use the CPU. The script describes this as a mechanism to prevent a single process from monopolizing the CPU, ensuring that multiple processes get a chance to execute. It is a key aspect of process management and affects system responsiveness and performance.

💡Context Switch

A 'context switch' occurs when the CPU switches from executing one process to another. The script mentions this in the context of preemption and multitasking, explaining that when the operating system decides to run a different process, it performs a context switch, which involves saving the state of the current process and loading the state of the next process to be executed.

💡Process Control Block

The 'process control block' (PCB) is a data structure that stores information about a process. The script describes the various details a PCB contains, such as the process's current state, unique ID, privileges, pointer to the next instruction, CPU register data, scheduling information, virtual memory allocation, and file descriptors. The PCB is crucial for the operating system to manage and track each process effectively.

💡Time Slice

A 'time slice' is the time limit assigned to a process for its execution on the CPU. The script explains that this mechanism, known as preemptive multitasking, allows the CPU to execute small parts of different processes at various times, preventing any single process from running for an extended period and ensuring that other processes get CPU time. The time slice is an important concept for balancing process execution and system responsiveness.

Highlights

A process is defined as an instance of a program loaded into memory, serving as a unit of work in an operating system.

The operating system is responsible for task management, including the execution of programs on the CPU.

A program must be compiled into an executable binary file before it can be executed on the CPU.

The operating system creates a process object in memory when a binary file is launched for execution.

A process is initially in a 'new' state and transitions to 'ready' when it's prepared to run on the CPU.

The scheduler is a dedicated component of the operating system that selects processes to run on the CPU.

Preemption is the behavior where the operating system moves a running process back to the ready state to allow other processes to use the CPU.

A process can enter a 'waiting' state if it requires external resources, such as data over a network.

The process lifecycle includes states such as new, ready, running, waiting, and terminated.

Having multiple CPU cores allows for parallel processing, increasing system throughput.

Preemptive multitasking ensures that no single process monopolizes the CPU, allowing for a responsive system.

The time limit for CPU usage by a process is known as the time slice, which is typically 100 milliseconds on Linux.

Context switch is the operation of changing the process currently running on the CPU with another.

Process information is stored in a data structure called the process control block, which can vary by operating system.

The process control block contains details such as the process state, unique ID, privileges, and scheduling information.

Different types of systems, like user-oriented or server-side, have different scheduling priorities due to their specific needs.

The lecture provides a comprehensive overview of processes in the context of an operating system, highlighting their lifecycle and management.

Transcripts

play00:00

all right so in this first lecture we're

play00:01

going to see what actually is a process

play00:03

in an operating system

play00:06

so first if we take a look on the

play00:07

conceptual architecture of a computer we

play00:09

know that at the bottom we got the

play00:11

hardware which contains the cpu the

play00:13

memory and devices like peripherals and

play00:15

other external components

play00:17

on top of that we got the first software

play00:19

layer in a computer which is the

play00:21

operating system

play00:23

and based on that we got the

play00:24

applications layer which contains all

play00:26

the applications managed by the user

play00:29

the operating system is a very complex

play00:31

component with lots of responsibilities

play00:33

like security performance and many

play00:35

others

play00:36

but probably one of the most important

play00:38

ones is task management and by task i'm

play00:40

referring to any program that should be

play00:42

executed on the cpu which is launched by

play00:44

the user or by the operating system

play00:46

itself

play00:48

so let's see in more detail how this

play00:50

works

play00:52

let's say we have a program which is

play00:53

just a text file with instructions

play00:55

stored on the local disk

play00:58

to be able to run it on the cpu we need

play01:00

to compile it to get an executable

play01:02

binary file which can be a jar an exe or

play01:06

any other executable format

play01:08

that is also stored on the local disk

play01:11

now when we launch the binary file into

play01:13

the execution

play01:14

the operating system will create a

play01:15

process object that is stored into the

play01:18

memory in that case

play01:20

from now on the process will be

play01:21

completely managed by the operating

play01:23

system

play01:26

so if we have to define a process we can

play01:28

say that a process is an instance of a

play01:30

program loaded into memory

play01:33

or more generically a process is a unit

play01:36

of work in an operating system

play01:39

keep in mind that a process is not an

play01:41

active entity it's just an object stored

play01:44

in memory that contains information

play01:45

about the execution of a particular

play01:47

program

play01:49

a process always has a state when you

play01:52

create a process its initial state will

play01:54

be new

play01:56

when the process is able to be run on

play01:57

the cpu it will immediately transition

play01:59

to the ready state

play02:02

the operating system has a dedicated

play02:04

component called scheduler which is

play02:06

responsible for selecting processes from

play02:08

the ready state and placing them onto

play02:10

the cpu in order to be executed

play02:14

the process runs on the cpu for a while

play02:16

and it can be moved to the ready state

play02:18

by the operating system when it decides

play02:20

to let other processes to use the cpu

play02:23

this behavior is called preemption and

play02:25

we'll take a closer look on how it works

play02:27

further in this lecture

play02:30

a running process can also be moved into

play02:32

the waiting state if it needs to wait

play02:34

for some external resources like for

play02:36

some data that needs to be received over

play02:38

the network for example

play02:40

and finally when the process does not

play02:42

have any other instructions to be

play02:44

executed it will move to the terminated

play02:46

state

play02:47

now let's assume that we have one cpu

play02:49

core and we got three processes launched

play02:51

by the user and we want to see how those

play02:53

processes move through those states

play02:56

usually if the system has enough

play02:58

capacity the processes will move

play03:00

directly to the ready state

play03:02

the scheduler picks one process based on

play03:04

a well-defined algorithm and moves it

play03:07

into the running state

play03:09

it picks only one process because there

play03:10

is only one cpu core available

play03:14

the chosen process runs for a while on

play03:15

the cpu and then it needs access to some

play03:17

external resource which may take some

play03:20

time so it gets moved into the waiting

play03:21

state

play03:23

as soon as the cpu is free the scheduler

play03:25

immediately takes another process and

play03:27

moves it into the running state

play03:30

the waiting process receives the data

play03:32

from the external component and moves

play03:33

into the ready state ready to be picked

play03:36

by the scheduler again

play03:38

the currently running process is

play03:40

preempted by the operating system

play03:41

because its time slice has elapsed

play03:44

and the workflow continues until all the

play03:46

instructions of the processes are

play03:47

executed and they move to the terminated

play03:49

state

play03:51

this workflow is actually called the

play03:53

process lifecycle

play03:55

now if you have three cpu cores for

play03:57

example we will be able to handle three

play03:59

processes in parallel which triples the

play04:02

throughput of the entire system

play04:05

now let's take a look on what preemption

play04:06

really is

play04:08

let's imagine we have a single cpu core

play04:11

and we have a process that is called

play04:13

clock which is responsible for simply

play04:15

printing the current time on the screen

play04:18

if that process is the only one that is

play04:19

running on the cpu the system will

play04:21

become unresponsive because there are

play04:23

other processes that need to use the cpu

play04:26

like your browser or the ui components

play04:28

of the operating system

play04:30

so to solve that issue each process is

play04:32

assigned a particular time limit during

play04:34

which it's able to use a cpu

play04:37

in that way the cpu will execute small

play04:39

parts of a process at different times

play04:41

rather than executing the same process

play04:43

for a large amount of time leaving space

play04:45

for other processes to be executed

play04:48

this mechanism is called preemptive

play04:50

multitasking and it should always be

play04:52

preceded with a trade-off in mind

play04:54

because operating systems that are user

play04:56

oriented like windows mac os ubuntu and

play04:59

others need to be responsive so

play05:02

processes related to ui components are

play05:04

likely to be scheduled more on the cpu

play05:06

by leveraging the preemptive

play05:07

multitasking

play05:09

on the other hand server-side systems

play05:11

like windows server or ubuntu server

play05:13

usually need performance rather than

play05:15

responsiveness so their scheduler will

play05:17

likely favor long-running processes

play05:20

so basically you should have in mind the

play05:22

type of the workload you're currently

play05:24

running to see if too much multitasking

play05:26

can become a problem

play05:28

now regarding the time limit for which

play05:30

processes should execute on the cpu

play05:32

it actually has a name it's called time

play05:34

slice

play05:35

and its value is usually 100

play05:37

milliseconds on linux but it's

play05:39

dynamically adjusted by the operating

play05:41

system anyway so you can't really tell

play05:42

which value it has at any given time

play05:45

when the process being run on the cpu is

play05:47

changed with another one

play05:49

this operation is called context switch

play05:51

and we'll see in the next lectures why

play05:52

this operation could become a problem in

play05:54

terms of performance

play05:57

now the last important aspect that we

play05:59

need to know about the process is the

play06:00

actual information that is stores we

play06:02

just saw previously that a process lives

play06:04

in the memory but what it actually

play06:06

contains

play06:08

well first it needs to contain the

play06:09

current state that it has running

play06:11

waiting terminated or any other state a

play06:14

unique id which is just a number to

play06:15

identify the process

play06:18

some privileges that specify on which

play06:20

resources the process has access to

play06:23

a pointer to the next extraction that

play06:24

needs to be executed

play06:26

the data that was stored in the cpu

play06:27

registers when the process was switched

play06:29

off the cpu

play06:31

some information related to the

play06:33

scheduling process like priority for

play06:34

example

play06:36

information related to the virtual

play06:38

memory currently allocated by the

play06:39

process

play06:41

a pointer to the parent process and some

play06:43

information related to which file

play06:44

descriptors are being used

play06:47

this data structure is called process

play06:49

control block

play06:50

and its content can slightly vary

play06:52

depending on the operating system

play06:55

so that's pretty much all you need to

play06:57

know about the process in the context of

play06:59

multithreading

Rate This

5.0 / 5 (0 votes)

関連タグ
Operating SystemProcess ManagementTask ExecutionCPU SchedulingPreemptive MultitaskingProcess StatesContext SwitchTime SliceProcess Control BlockSystem Performance
英語で要約が必要ですか?