Podcast
Questions and Answers
Which of the following best describes a process?
Which of the following best describes a process?
- A program stored on disk
- A type of memory allocation
- A program in execution (correct)
- A hardware component
A thread is a program in execution.
A thread is a program in execution.
False (B)
What is the purpose of multitasking in an operating system?
What is the purpose of multitasking in an operating system?
To execute multiple processes concurrently by time-sharing the CPU
In the context of processes, I/O-bound processes spend more time waiting for ________ completion than performing computations.
In the context of processes, I/O-bound processes spend more time waiting for ________ completion than performing computations.
Match the Chrome browser process types with their functions:
Match the Chrome browser process types with their functions:
What is the primary function of the process state?
What is the primary function of the process state?
A process transitions between states only when manually triggered by the user.
A process transitions between states only when manually triggered by the user.
What is the purpose of a Process Control Block (PCB)?
What is the purpose of a Process Control Block (PCB)?
The PCB contains the __________, which specifies the address of the next instruction to be executed by the process.
The PCB contains the __________, which specifies the address of the next instruction to be executed by the process.
Match the elements of a PCB with their functions:
Match the elements of a PCB with their functions:
What is the main objective of process scheduling?
What is the main objective of process scheduling?
In a single-processor system, multiple processes can run simultaneously.
In a single-processor system, multiple processes can run simultaneously.
What is the purpose of the ready queue in process scheduling?
What is the purpose of the ready queue in process scheduling?
The _________ scheduler selects processes from a pool and loads them into memory for execution.
The _________ scheduler selects processes from a pool and loads them into memory for execution.
Match types of the following schedulers with their descriptions:
Match types of the following schedulers with their descriptions:
What is the main reason for context switching?
What is the main reason for context switching?
Context switch time is productive time, as it directly contributes to useful work.
Context switch time is productive time, as it directly contributes to useful work.
In the context on context switching, what does saving the context mean?
In the context on context switching, what does saving the context mean?
The overhead of context switching typically occurs in _________.
The overhead of context switching typically occurs in _________.
Match the steps taken for context switch
Match the steps taken for context switch
What is the term for a process that creates new processes?
What is the term for a process that creates new processes?
Child processes always have the same process ID (PID) as their parent process.
Child processes always have the same process ID (PID) as their parent process.
What is the significance of the pid
variable?
What is the significance of the pid
variable?
A process in Unix can terminate by calling the _______ system call.
A process in Unix can terminate by calling the _______ system call.
Match the resource sharing
Match the resource sharing
What is inter-process communication (IPC)?
What is inter-process communication (IPC)?
Independent processes can affect or be affected by other processes in the system.
Independent processes can affect or be affected by other processes in the system.
What are the advantages or needs for Inter-Process Communication?
What are the advantages or needs for Inter-Process Communication?
In IPC, a ________ is defined as an endpoint for communication over a network.
In IPC, a ________ is defined as an endpoint for communication over a network.
Match the following IPC methods with their description:
Match the following IPC methods with their description:
In the Producer-Consumer model, what happens when produced items arrive faster than they are consumed?
In the Producer-Consumer model, what happens when produced items arrive faster than they are consumed?
In the shared memory model for IPC, processes communicate by exchanging messages through a mailbox.
In the shared memory model for IPC, processes communicate by exchanging messages through a mailbox.
What is the role of buffers in the producer-consumer model?
What is the role of buffers in the producer-consumer model?
In message passing, the send()
and recv()
operations can be ______ or non-blocking.
In message passing, the send()
and recv()
operations can be ______ or non-blocking.
Match these statements
Match these statements
Which of the following best describes pipes?
Which of the following best describes pipes?
Pipes are bidirectional by default, allowing data to flow in both directions simultaneously.
Pipes are bidirectional by default, allowing data to flow in both directions simultaneously.
How can standard I/O redirection create a pipe?
How can standard I/O redirection create a pipe?
Using standard I/O redirection, >
redirects the output of a program or a command into a specified ____________.
Using standard I/O redirection, >
redirects the output of a program or a command into a specified ____________.
Match each file dscriptor using Pipes:
Match each file dscriptor using Pipes:
When a process terminates but its PCB remains in memory, what is this process called?
When a process terminates but its PCB remains in memory, what is this process called?
Flashcards
What is a Process?
What is a Process?
A program in execution; an instance of a program running.
What is a Thread?
What is a Thread?
A basic unit of CPU utilization, consisting of a program counter, stack, and a set of registers.
What is Multitasking?
What is Multitasking?
Executing multiple processes concurrently, giving the illusion of parallelism.
What is Process State?
What is Process State?
Signup and view all the flashcards
How many process states are there?
How many process states are there?
Signup and view all the flashcards
What is a PCB? (Process Control Block)
What is a PCB? (Process Control Block)
Signup and view all the flashcards
What is Context Switch?
What is Context Switch?
Signup and view all the flashcards
What is a Process ID?
What is a Process ID?
Signup and view all the flashcards
What is Process State?
What is Process State?
Signup and view all the flashcards
What is Program Counter?
What is Program Counter?
Signup and view all the flashcards
What are CPU Registers?
What are CPU Registers?
Signup and view all the flashcards
What is CPU Scheduling Information?
What is CPU Scheduling Information?
Signup and view all the flashcards
What is Memory Management Information?
What is Memory Management Information?
Signup and view all the flashcards
What is Accounting Information?
What is Accounting Information?
Signup and view all the flashcards
What is I/O Status Information?
What is I/O Status Information?
Signup and view all the flashcards
What is Process Scheduler?
What is Process Scheduler?
Signup and view all the flashcards
What are common Scheduling Queues?
What are common Scheduling Queues?
Signup and view all the flashcards
What does a Long-Term Scheduler do?
What does a Long-Term Scheduler do?
Signup and view all the flashcards
What does a Short-Term Scheduler do?
What does a Short-Term Scheduler do?
Signup and view all the flashcards
What does a Medium-Term Scheduler do?
What does a Medium-Term Scheduler do?
Signup and view all the flashcards
Context switch
Context switch
Signup and view all the flashcards
What is Process Creation?
What is Process Creation?
Signup and view all the flashcards
What happens after process creation?
What happens after process creation?
Signup and view all the flashcards
What is Process Termination?
What is Process Termination?
Signup and view all the flashcards
What is Inter-Process Communication (IPC)?
What is Inter-Process Communication (IPC)?
Signup and view all the flashcards
What types of processes are there?
What types of processes are there?
Signup and view all the flashcards
What are Independent Processes?
What are Independent Processes?
Signup and view all the flashcards
What are Cooperating Processes?
What are Cooperating Processes?
Signup and view all the flashcards
What is Inter-Process Communication (IPC)?
What is Inter-Process Communication (IPC)?
Signup and view all the flashcards
What is the need for Inter-Process Communication?
What is the need for Inter-Process Communication?
Signup and view all the flashcards
What is Shared Memory IPC?
What is Shared Memory IPC?
Signup and view all the flashcards
What is Message Passing IPC?
What is Message Passing IPC?
Signup and view all the flashcards
What is Pipes?
What is Pipes?
Signup and view all the flashcards
What is message Socket?
What is message Socket?
Signup and view all the flashcards
What are Pipes?
What are Pipes?
Signup and view all the flashcards
What are Process job/ready Queue
What are Process job/ready Queue
Signup and view all the flashcards
What are Process Queues?
What are Process Queues?
Signup and view all the flashcards
What are Producer-Consumer Model?
What are Producer-Consumer Model?
Signup and view all the flashcards
What are unidirectional flows?
What are unidirectional flows?
Signup and view all the flashcards
Using Command Pipes in CLI
Using Command Pipes in CLI
Signup and view all the flashcards
Study Notes
- Education is a powerful tool for changing the world, as stated by Nelson Mandela
Processes
- Covers process definition, management, states, scheduling, context switching, and inter-process communication
- Learning outcomes include defining processes, differentiating between processes and threads, understanding multitasking and process states
- Aims to teach process operations (creation, termination, communication) and the Producer-Consumer model
Process Definition and Management
- Program source code written in a high-level language like C++/Java is transformed into machine-readable code
- A compiler transforms the code that operating system loads into computer memory for program execution, allocating resources as needed
Process vs. Thread
- A process is a program in execution
- A thread is a unit of execution within a process
- A process can have one or more threads
Multitasking
- Processes spend time on I/O activities, which is slower than CPU processing
- Multitasking happens when the OS runs multiple processes concurrently by time-sharing hardware
Chrome Browser Example
- Chrome uses multiple processes: a browser process for the UI and network I/O, renderer processes for web pages and HTML parsing, and plug-in processes like Adobe Flash Player
- Adobe Flash Player enables viewing multimedia content, executing rich internet applications, and streaming audio/video
Process State
- The state is defined by the current activity
- When executing, a process changes states
Five Process States
- New: The process is being created
- Running: Instructions are being executed
- Waiting: Waiting for an event (I/O completion or a signal)
- Ready: Waiting to be assigned to a processor
- Terminated: The process has finished execution
Diagram of Process State
- Illustrates transitions between New, Ready, Running, Waiting, and Terminated states via events like interrupts, scheduler dispatch, and I/O
Process Control Block (PCB)
- Each process runs in the OS and is tracked via a PCB - sometimes called a task control block
- PCB represents a process in the Operating System
PCB Contents
- Process ID: Unique identifier
- Process State: Current state (New, Waiting, etc.)
- Program Counter: Points to the next instruction to be executed
- CPU Registers: Registers used by process
- CPU Scheduling Information: Process priority, scheduling queue
- Memory Management Information: Memory used by the process
- Accounting Information: Resources used (CPU, time, memory)
- I/O Status Information: I/O devices assigned
PCB in Linux
- Linux maintains a doubly-linked list of processes using the C structure task_struct
Process Scheduling
- Multiprogramming maximizes CPU use by running a process all the time
- Time sharing switches the CPU between processes, and allows user interaction
- The process scheduler makes program accessible for the CPU to run it
Single Processor System
- Only one process can run at the same time on a computer
Scheduling Queues
- Job Queue: Contains all processes in the system
- Ready Queue: Contains processes residing in main memory, ready and wait time
Schedulers
- Long-term (job) scheduler: Selects processes from a storage pool and loads them into memory
- Short-term (CPU) scheduler: Selects from ready processes and allocates the CPU
- Medium-Term Scheduler: Part of swapping, removes processes from memory to reduce multiprogramming, manages swapped-out processes
Context Switch
- The operating system has to save the current context of the process that's currently running on the CPU so that it can restore that context when its processing is done, suspending the process and then resuming it
- The PCB stores it in the context
Concept of Context
- Interrupts cause the OS to switch the CPU from the current task to a kernel routine
- The system saves the current process context (state) for later restoration
Context Switch Details
- A context switch occurs when a CPU core switches from one process to another
- The OS saves the context of the current process and loads the context of the new process
- A scheduler decides when to perform a context switch and selects the next process, this occurs in the kernel
Context Switch Performance
- Context switch time is pure overhead
- Speed varies depending on memory speed and registers
- Typical speeds are milliseconds
Operation on Processes: Creation
- Via a create process-system call, a process can create several new processes
- The creating process is considered the parent process, and the new processes are called the children.
- Each process has a unique pid (process identifier), usually an integer
Process Creation Options
-
Parent can execute concurrently with its children
-
The parent can wait until some or all of its children are terminated
-
The child is a duplicate of the parent
-
The child uses a new program loaded
Process Creation in UNIX and Windows:
- UNIX programs use fork() to create a new process, exec() to replace its image, exit() to terminate, and wait() for child processes
- Windows uses CreateProcess() to specify the command to execute in a child process; it does not support fork()
Process Termination
- A process ends by calling exit()
- The parent recovers the status via wait().
- The PCB waits until the parent calls wait() and becomes a zombie process
- The kernel can also "kill" a process
Inter-Process Communication (IPC)
- Concurrent processes are either independent or cooperating
- IPC is needed in cooperating processes
Needs for Inter-Process Communication
- Information sharing
- Computation speedup
- Convenience
IPC Methods
- Shared Memory: A shared memory region is established with cooperating processes
- Message Passing: Uses messages exchanged between processes
- Pipes: Functions like shared files, with one process writing and another reading (unidirectional)
- Sockets: Endpoints for communication, identified by IP address and port number
Producer-Consumer Model
- A common IPC pattern involves a producer and a consumer which run concurrently
- Buffering is needed to handle variable production/consumption rates
- A buffer has a limited size, so it's also called a bounded-buffer problem
Example Practical Implementations
- I/O device drivers act as producers, collecting input that applications (consumers) process
- Print spooling involves applications sending files to a folder
- After this a spooler process sends them to the printer one at a time
Shared Memory
- Different memory accessible by different processes in a bidirectional manner
Shared Memory: Consumer-Producer Model
- Uses a memory area that the accessing processes use
- Producer and consumer utilize a shared buffer
Key Concepts
- Processes have unique memory spaces
- The OS provides special ways to allocate memory that can be shared across processes
- The code given in the previous slide is not synchronized!!
Key Considerations of shared memory and Message passing
- Shared memory allows processes to allocate memory for use in several processes
- OS provides special ways to allocate this memory, these have to be created explicitly with more configuration than message passing
- Sharing memory only works with systems the memory across them, and this implementation requires a kernel
Message Passing
- Uses direct links with send(pid, msg) and recv(pid, msg)
- Uses indirect links with mailboxes send(mbox, msg) and recv(mbox, msg)
- send() and recv() can be blocking or non-blocking, some apps utilize these for synchronization
Message Passing: Consumer-Producer Model
- Consumer reads from the producer
- Producer sends message to consumer
Characteristics of Shared Memory and Message Passing
- Shared memory requires system calls only to establish shared regions, then accesses work as routine memory accesses
- Message passing requires more kernel intervention, is useful for small data, and is easier to implement in distributed systems
Pipes
- Acts like having an intermediate file where one process writes and the other process reads, pipes exist in main memory
- The system calls used to read and write to/from a pipe mirror file accessing
- Examples are READ() and WRITE()
Two pipe types
- Ordinary pipe in UNIX (Anonymous pipes in Windows) work by creating a parent that connects to a child process to create a line of communication
- Named pipe - also known as AKA FIFO makes information accessible by process
- In both cases Pipe is Unidirectional, but two pipes can be added to ensure that you can create two lines of pipes in different directions
Pipes In Code
- In code a descriptor fd[0] is for reading and fd[1] is for writing
- If the program is connected, the data written in fd[1] can be read from fd[0]
Pipes in Command Line Interface (CLI)
- CLI creates pipes between two programs where you can redirect input and output
- You can redirect the output of a command into a specified file by adding the redirector, represented by ">"
- The Pipe symbol "|" pipes the output of the first command, and pipes it directly as in input into the second command
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.