Quiz 2 Flashcards
What is the difference between a program and a process?
A process is simply a program that is currently in execution.
What are the different components of a process?
The program code, or the text section.
Current activity including program counter, processor registers.
Stack containing temporary data - Function parameters, return addresses, local variables
Data section containing global variables
Heap containing memory dynamically allocated during run time.
What are the process states?
New: The process is being created
Running: Instructions are being executed
Waiting: The process is waiting for some event to occur
Ready: The process is waiting to be assigned to a processor
Terminated: The process has finished execution
What is process scheduling/scheduler?
Maximizes CPU use, quickly switches processes onto CPU core. Process scheduler selects among available processes for next execution on CPU core. Maintains scheduling queues of processes.
What are ready and wait queues?
Ready queue - Set of all processes residing in main memory, ready and waiting to execute
Wait queues - Set of processes waiting for an event (i.e. I/O)
What is a context switch?
When a CPU switches to another process the system must save the state of the old process and load the saved state for the new process via a context switch.
What is the PCB?
A context of a process is represented in the Program Control Block or PCB.
How is time related to context switching?
Context-switch time is overhead, the system does no useful work while switching. The more complex the OS and the PCB the longer the context switch. Some hardware provides multiple sets of registers per CPU meaning multiple contexts loaded at once.
What does process creation mean?
A parent process creates child processes, which in turn create other processes, forming a tree of processes.
Generally process identified and managed via a process identifier (pid)
When a parent creates a new child process what are the possibilities in terms of execution and address space for the new process.
Resource Sharing:
- Parent and child share all resources
- Children share subset of parent’s resources
- Parent and child share no resources.
Execution options
- Parent and child execute concurrently
- Parent waits until children terminate.
What are some unix commands associated with process creation?
fork() - Creates a new process
exec() - System call used after fork() to replace the process’ memory space with a new program.
exit() - Terminates a child process
wait() - Parent processes will wait for the child to terminate.
What does process termination mean?
Process executes last statement and then asks the operating system to delete it using the exit() system cal.
- Returns status data from child to parent (via wait())
- Process’ resources are deallocated by operating system.
How does a parent terminate a child process? Why would this be done?
A parent may terminate the execution of children processes using the abort() system call. Some reasons for doing so:
- The child has exceeded allocated resources
- Task assigned to child is no longer required
- The parent is exiting and the operating system does not allow a child to continue if its parent terminates.
What is cascading termination?
Some operating systems do not let a child exist if its parent has terminated. Therefore when a process terminates all its children must also be terminated. Cascading termination refers to the process of all children, grandchildren etc. processes of a process being terminated.
What are the two types of processes within a system?
Independent - Process cannot affect or be affected by the execution of another process
Cooperating - Process can affect or be affected by the execution of another process
What are some reasons for using cooperating processes?
- Information sharing
- Computation speedup
- Modularity
- Convenience
What is the IPC and what are the models?
Interprocess communication is required for cooperating processes.
Models are
- Shared Memory
- Message Passing
What is the producer-consumer problem?
Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process.
- unbounded buffer places no practical limit on the size of the buffer
- bounded buffer assume that there is a fixed buffer size.
What is the shard memory model?
An area of memory shared among cooperating processes that wish to communicate.
The communication is under the control of the users processes not the operating system.
Major issue is to provide mechanism that will allow the user processes to synchronize their actions when they access shared memory.
What is the message passing model?
- Mechanism for cooperating processes to communicate and synchronize their actions.
- Message system - processes communicate with each other without resorting to shared variables.
- IPC facility provides two operations: send(message) and receive(message)
- The message size can be either fixed of variable.
How do two processes communicate in the message passing model?
The processes must establish a communication link between them and exchange messages via send/receive commands.
What are some implementation issues of the message passing model?
- How are links established?
- Can a link be associated with more than two processes?
- How many links can there be between every pair of communicating processes?
- What is the capacity of a link?
- Is the size of a message that the link can accommodate fixed or variable?
- Is a link unidirectional or bi-directional?
What is direct communication?
-Processes must name each other explicitly:
send(P, message) - Send a message to process P
receive(Q, message) - receive a message from process Q
- Links are established automatically
- A link is associated with exactly one pair of communicating processes
- Between each pair there exists exactly one link
- The link may be unidirectional but it is usually bi-directional.
What is indirect communication?
Messages are directed and received from mailboxes or ports.
-Each mailbox has a unique ID processes can communicate only if they share a mailbox.
- Link established only if processes share a common mailbox
- A link may be associated with many processes
- Each pair of processes may share several communication links
- Link may be unidirectional or bi-directional
What are so operations of indirect communication?
-Create a new mailbox (port)
-Send and receive messages through mailbox:
send(A, message) - Send a message to mailbox A
receive(A, message) - Receive a message from mailbox A
-Destroy a mailbox
What is synchronization?
Message passing may be either blocking or non-blocking.
Blocking is considered synchronous
Blocking send - The sender is blocked until the message is received.
Blocking receive - The receiver is blocked until a message is available.
Non-blocking is considered asynchronous
Non-blocking send - The sender sends the message and continues.
Non-blocking receive - The receiver receives a valid message or a null message.
What is a thread?
A thread is a line of execution within a program.
What are some tasks that can be implemented by separate threads?
- Update display
- Fetch data
- Spell checking
- Answer a network request
What’s the difference between process creation and thread creation?
Process creation is heavy-weight while thread creation is light-weight
What are the benefits of multi-threaded programming?
Responsiveness – may allow continued execution if part of process is blocked, especially important for user interfaces
Resource Sharing – threads share resources of process, easier than shared memory or message passing
Economy – cheaper than process creation, thread switching lower overhead than context switching
Scalability – process can take advantage of multicore architectures
What is multicore programming?
Multicore or multiprocessor systems putting pressure on programmers, challenges include:
- Dividing activities
- Balance
- Data splitting
- Data dependency
- Testing and debugging
What is the difference between parallelism and concurrency?
Parallelism implies a system can perform more than one task simultaneously
i.e. Having multiple cores, each executing commands at the same time
Concurrency supports more than one task making progress
Single processor / core, scheduler providing concurrency
i.e. Having one core executing commands intertwined with each other.
What are the types of parallelism?
Data parallelism – distributes subsets of the same data across multiple cores, same operation on each
Task parallelism – distributing threads across cores, each thread performing unique operation
What are user threads?
Management done by user-level threads library Three primary thread libraries: POSIX Pthreads Windows threads Java threads
What are kernel threads?
Threads supported by the Kernel Examples – virtually all general purpose operating systems, including: Windows Linux Mac OS X iOS Android
What is the many-to-one model?
- Many user-level threads mapped to single kernel thread
- One thread blocking causes all to block
- Multiple threads may not run in parallel on multicore system because only one may be in kernel at a time.
- Few systems currently use this model. Solaris Green Threads and GNU Portable Threads are two examples.
What is the one-to-one model?
- Each user-level thread maps to kernel thread
- Creating a user-level thread creates a kernel thread
- More concurrency than many-to-one
- Number of threads per process sometimes restricted due to overhead
- Examples
- Windows
- Linux
What is the many-to-many model?
- Allows many user level threads to be mapped to many kernel threads
- Allows the operating system to create a sufficient number of kernel threads
- Windows with the ThreadFiber package
- Otherwise not very common
What are thread libraries?
Thread library provides programmer with API for creating and managing threads
Two primary ways of implementing
- Library entirely in user space
- Kernel-level library supported by the OS
What are Pthreads?
- May be provided either as user-level or kernel-level
- A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization
- Specification, not implementation
- API specifies behavior of the thread library, -implementation is up to development of the library
- Common in UNIX operating systems (Linux & Mac OS X)
What is thread-local storage?
- Thread-local storage (TLS) allows each thread to have its own copy of data
- Useful when you do not have control over the thread creation process (i.e., when using a thread pool)
- Different from local variables
- Local variables visible only during single function invocation
- TLS visible across function invocations
- Similar to static data
- TLS is unique to each thread