Rss Feed
User Threads
[ ] Thread management done by user-level threads library
[ ] No support from the kernel (The kernel is not aware of the existence of threads)
[ ] Fast to create and manage
[ ] Block all threads for a blocking system call if the kernel is single threaded
[ ] Cannot take advantage of multi-processors
 Three primary thread libraries:
 POSIX Pthreads
 Win32 threads
 Java threads

BENEFITS OF MULTITHREADED PROGRAMMING

BENEFITS

 Responsiveness

 Resource Sharing

 Economy

 Utilization of MP Architectures

INTERPROCESS COMMUNICATION
- - -is a set of techniques for the exchange of data among multiple threads in one or more processes. Processes may be running on one or more computers connected by a network. IPC techniques are divided into methods for message passing, synchronization, shared memory, and remote procedure calls (RPC). The method of IPC used may vary based on the bandwidth and latency of communication between the threads, and the type of data being communicated. - - -
DIRECT COMMUNICATION
[ ] Sender/receiver refer to each other, as seen before
[ ] Properties of communication link
Link is established automatically between communicating processes
Link is associated with exactly two processes
Exactly one link for every pair of processes
[ ] Communication is symmetric (above) or asymmetric
send(P,m) // send a message to P
receive(&id, m) // receive from any process, set id to sender
INDIRECT COMMUNICATION


[ ] Communication via mailboxes (or ports)

[ ] Processes communicate by putting and taking messages in/from mailboxes

send(A, m) and receive(A,m)

[ ] Properties of communication link

A link is established between two processes, if they share a mailbox
Link maybe associated with more than two processes
A number of different links may exist between any pair of processes; each one a separate mailbox


SYNCHRONIZATION

- - - is timekeeping which requires the coordination of events to operate a system in unison. The familiar conductor of an orchestra serves to keep the orchestra in time. Systems operating with all their parts in synchrony are said to be synchronous or in sync. Some systems may be only approximately synchronized, or plesiochronous. For some applications relative offsets between events need to be determined, for others only the order of the event is important. - - -


[ ] BLOCKING SEND – sender blocked until message is received by receiver (or by mailbox)

[ ] NON - BLOCKING SEND – sending process resumes operation right after sending

[ ] BLOCKING RECEIVE – receiver blocks until message is available

[ ] NON - BLOCKING RECEIVE – receiver retrieves a valid message or returns an error code


BUFFERING

[ ] Zero capacity – queue has length 0, no messages can be outstanding on link, sender blocks for
message exchange

[ ] Bounded capacity – queue has length N, N messages can be in queue at any point in time, sender blocks if queue is full, otherwise it may continue to execute

[ ] Unbounded capacity – queue has infinite length, sender never blocks


PRODUCER COUNTER EXAMPLE


[ ] PRODUCER – generates an integer between 0 and 9 (inclusive), then stores it in a CubbyHole object. To make the synchronization problem more interesting, the Producer sleeps for a random amount of time between 0 and 100 milliseconds before repeating the number generating cycle.

[ ] CONSUMER – consumes all integers from the CubbyHole (the exact same object into which the Producer put the integers in the first place) as quickly as they become available.
Interprocess Communication (IPC)
[ ] Mechanism for processes to communicate and to synchronize their actions.
[ ] Message system – processes communicate with each other without resorting to shared variables.
[ ] IPC facility provides two operations:
* send(message) –message size fixed or variable
* receive(message)
[ ] If P and Q wish to communicate, they need to:
* establish a communication link between them
* exchange messages via send/receive
[ ] Implementation of communication link
* physical (e.g., shared memory, hardware bus) considered later
* logical (e.g., logical properties) now
Cooperating Processes
[ ] 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
[ ] Advantages of process cooperation:
* Information sharing
* Computation speed-up
* Modularity
* Convenience
Operations on Processes

Process Creation

[ ] Parent process creates children processes, which, in turn create other processes, forming a tree of processes.
* Resource sharing
[ ] Parent and children share all resources.
[ ] Children share subset of parent’s resources.
[ ] Parent and child share no resources.
* Execution
* Parent and children execute concurrently.
* Parent waits until children terminate.
[ ] Address space
* Child duplicate of parent.
* Child has a program loaded into it.
[ ] UNIX examples
* fork system call creates new process
* fork returns 0 to child , process id of child for parent
* exec system call used after a fork to replace the process’ memory space with a new program.



Process Termination

[ ] Process executes last statement and asks the operating system to delete it (exit).
* Output data from child to parent (via wait).
* Process’ resources are deallocated by operating system.
[ ] Parent may terminate execution of children processes (abort).
* Child has exceeded allocated resources.
* Task assigned to child is no longer required.
* Parent is exiting.
= Operating system does not allow child to continue if its parent terminates.
= Cascading termination.
* In Unix, if parent exits children are assigned init as parent
Process Scheduling


Scheduling Queue

[ ] The operating System must allocate resources to processes, enable processes to share and exchange information, protect the resources of each process from other processes and enable synchronization amongst process.

[ ] Job queue – set of all processes in the system.

[ ] Ready queue – set of all processes residing in main memory, ready and waiting to execute.

[ ] Device queues – set of processes waiting for an I/O device.

[ ] Processes migrate between the various queues.


Schedulers

[ ] Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue.

[ ] Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU.

[ ] Short-term scheduler is invoked very frequently (milliseconds) fi (must be fast).

[ ] Long-term scheduler is invoked very infrequently (seconds, minutes) fi (may be slow).

[ ] The long-term scheduler controls the degree of multiprogramming.

[ ] Processes can be described as either:

* I/O-bound process – spends more time doing I/O than computations, many short CPU bursts.

* CPU-bound process – spends more time doing computations; few very long CPU bursts.


Context Switch

[ ] When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process.

[ ] Context-switch time is overhead; the system does no useful work while switching.

[ ] Time dependent on hardware support.
The Concept of Process


[ ] An operating system executes a variety of programs


* Batch system – jobs
* Time-shared systems – user programs or tasks



[ ] Textbook uses the terms job and process almost interchangeably.

[ ] Process – a program in execution; process execution must progress in sequential fashion.

[ ] A process includes:


* program counter
* stack
* data section




Process State

[ ] As a process executes, it changes state

* 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.



Diagram of Process State




Process Control Block (PCB)

Information associated with each process.

[ ] Process ID
[ ] Process state
[ ] Program counter

[ ] CPU registers
[ ] CPU scheduling information
[ ] Memory-management information

[ ] Accounting information
[ ] I/O status information



Process Control Block (PCB) :

Threads

[ ] Results from a fork of a computer program into two or more concurrently running tasks.

[ ] The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process.

[ ] Multiple threads can exist within the same process and share resources such as memory, while different processes do not share these resources.


System Generation

A process that creates a particular and uniquely specified operating system; it combines user-specified options and parameters with manufacturer-supplied general-purpose or nonspecialized program subsections to produce an operating system (or other complex software) of the desired form and capacity. Abbreviated sysgen.
System Boot

Operating system must be made available to hardware so hardware can start it

  • Small piece of code – bootstrap loader, locates the kernel, loads it into memory, and starts it
  • Sometimes two-step process where boot block at fixed location loads bootstrap loader
  • When power initialized on system, execution starts at a fixed memory location
  • Firmware used to hold initial boot code
  • Virtual Machine

    - Is a software implementation of a machine (computer) that executes programs like a real machine.

    - Provides a complete system platform which supports the execution of a complete operating system (OS).

    - Takes the layered approach to its logical conclusion. It treats hardware and the operating system kernel as though they were all hardware.

    IMPLEMENTATION

    - Modes:
  • virtual user mode and virtual monitor mode,
  • Actual user mode and actual monitor mode
    -Time
  • Whereas the real I/O might have taken 100 milliseconds, the virtual I/O might take less time (because it is spooled) or more time (because it is interpreted.)
  • The CPU is being multi-programmed among many virtual machines, further slowing down the virtual machines in unpredictable ways.

    BENEFITS

    - concept provides complete protection of system resources since each virtual machine is isolated from all other virtual machines.

    - perfect vehicle for operating-systems research and development. System development is done on the virtual machine, instead of on a physical machine and so does not disrupt normal system operation.

    - multiple OS environments can co-exist on the same computer, in strong isolation from each other

    - the virtual machine can provide an instruction set architecture (ISA) that is somewhat different from that of the real machine

    - application provisioning, maintenance, high availability and disaster recovery

    EXAMPLE

    - A program written in Java receives services from the Java Runtime Environment (JRE) software by issuing commands to, and receiving the expected results from, the Java software. By providing these services to the program, the Java software is acting as a "virtual machine", taking the place of the operating system or hardware for which the program would ordinarily be tailored.

System Structure

Simple Structure

– any part of the system may use the functionality of the rest of
the system
– MS-DOS (user programs can call low level I/O routines)

Layered Approach

– layer n can only see the functionality that layer n-1 exports
– provides good abstraction from the lower level details
• new hardware can be added if it provides the interface required of a particular layer
– system call interface is an example of layering
– can be slow if there are too many layers
System Calls

Provide the interface between application programs and the kernel
Are like procedure calls

take parameters
calling routine waits for response
Permit application programs to access protected resources

Process Control

– create/terminate a process (including self)

File Management

– open, create
– read, write
close, delete
get or set file attributes

Also referred to as simply a file system or filesystem. The system that an operating system or program uses to organize and keep track of files. For example, a hierarchical file system is one that uses directories to organize files into a tree structure.

Although the operating system provides its own file management system, you can buy separate file management systems. These systems interact smoothly with the operating system but provide more features, such as improved backup procedures and stricter file protection.

Device Management

Device Management is a set of technologies, protocols and standards used to allow the remote management of mobile devices, often involving updates of firmware over the air (FOTA). The network operator, handset OEM or in some cases even the end-user (usually via a web portal) can use Device Management, also known as Mobile Device Management, or MDM, to update the handset firmware/OS, install applications and fix bugs, all over the air. Thus, large numbers of devices can be managed with single commands and the end-user is freed from the requirement to take the phone to a shop or service center to refresh or update.

Information Maintenance

get time
set system data (OS parameters)
get process information (id, time used)
Operating System Services


- Program execution – system capability to load a program into memory and to run it.

- I/O operations - since user programs cannot execute I/O operations directly, the operating system must provide some means to perform I/O.

- File-system manipulation – program capability to read, write, create, and delete files.

- Communications – exchange of information between processes executing either on the same computer or on different systems tied together by a network. Implemented via shared memory or message passing.

- Error detection – ensure correct computing by detecting errors in the CPU and memory hardware, in I/O devices, or in user programs.

OPERATING SYSTEM STRUCTURE

SYSTEM COMPONENTS


Operating Systems Process management

- In operating systems, process is defined as “A program in execution” [10]. Process can be
considered as an entity that consists of a number of elements, including: identifier, state, priority, program counter, memory pointer, context data, and I/O request. The above information about a process is usually stored in a data structure, typically called process block. Figure 1 shows a simplified process block [10]. Because process management involves scheduling (CPU scheduling, I/O scheduling, and so on), state switching, and resource management, process block is one of the most commonly accessed data type in operating system. Its design directly affects the efficiency of the operating system. As a result, in most operating systems, there is a data object that contains information about all the current active processes. It is called process controller. Figure 2 shows the structure of a process controller [10], which is implemented as a linked-list of process blocks. In order to achieve high efficiency, process controller is usually implemented as a global variable that can be accessed by both the kernel modules and nonkernel modules. For example, any time a new process (task) is created, the module that created this process should be able to access the process controller to add this new process. Therefore, process controller – the data object that controls the current active process – is usually implemented as a category-5 global variable. This means, both the kernel modules and nonkernel modules can access process controller to change its fields and these changes can affect the uses of process controller in kernel modules.
Main Memory Management
- the act of managing computer memory. In its simpler forms, this involves providing ways to allocate portions of memory to programs at their request, and freeing it for reuse when no longer needed. The management of main memory is critical to the computer system.
- tricky compromise between performance (access time) and quantity (available space). We always seek the maximum available memory space but we are rarely prepared to compromise on performance. Memory management must also perform the following functions:
> allow memory sharing (for a multi-threaded system);
> allocate blocks of memory space for different tasks;
> protect the memory spaces used (e.g. prevent a user from changing a task performed by another user);
> optimise the quantity of available memory, specifically via memory expansion systems.

File Management
- A file is a collection of related information defined by its creator. Commonly, files represent programs (both source and object forms) and data.
- The operating system is responsible for the following activities in connections with file management:

> File creation and deletion.
> Directory creation and deletion.
> Support of primitives for manipulating files and directories.
> Mapping files onto secondary storage.
> File backup on stable (nonvolatile) storage media.
INPUT / OUTPUT SYSTEM MANAGEMENT
- The I/O system consists of:
> A buffer-caching system
> A general device-driver interface
> Drivers for specific hardware devices
Secondary Storage System
- Main memory (primary storage) is volatile and too small to accommodate all data and programs permanently, the computer system must provide secondary storage to back up main memory.
- Modern computer systems use disks as the principle on-line storage medium, for both programs and data.
- The operating system is responsible for the following activities in connection with disk management:
> Free space management
> Storage allocation
> Disk scheduling
Protection System
- A mechanism for controlling access by programs, processes, or users to both system and user resources.

- The protection mechanism must:

> distinguish between authorized and unauthorized usage.
> specify the controls to be imposed.
> provide a means of enforcement.

Command Interpreter System

- Many commands are given to the operating system by control statements which deal with:

>process creation and management

>I/O handling
>secondary-storage management
>main-memory management
>file-system access
>protection
>networking