The threads library is implemented by time-sharing on a single processor. It will not take advantage of multi-processor machines. Using this library will therefore never make programs run faster. However, many programs are easier to write when structured as several communicating processes.
Two implementations of the threads library are available, depending on the capabilities of the operating system:
System threads. This implementation builds on the OS-provided threads facilities: POSIX 1003.1c threads for Unix, and Win32 threads for Windows. When available, system threads support both bytecode and native-code programs.
VM-level threads. This implementation performs time-sharing and context switching at the level of the OCaml virtual machine (bytecode interpreter). It is available on Unix systems, and supports only bytecode programs. It cannot be used with native-code programs.
Thursday, July 30, 2009
Thread Library
Posted by charrie at 4:15 AM 0 comments
Labels: OS5
Multithreading Models
Many systems provide support for both user and kernel threads, resulting in different multithreading models. There are three common types of threading implementation:
1. Many-to-one Model - maps many user-level threads to one kernel thread.
2. One-to-one Model - maps each user thread to a kernel thread. It provides mode concurrency than the many-to-one model by allowing another thread to run when a thread makes a blocking system call.
3. Many-to-many Model - The many-to-many model multiplexes many user-level threads to a smaller or equal number of kernel threads. The number of kernel threads may be specific to either a particular application or a particular machine.
Posted by charrie at 3:49 AM 0 comments
Labels: OS5
Thread
Threads
A process is a program that performs a single thread of execution. This single thread of control allows the process to perform only one task at one time. Many modern operating systems have extended process concept to allow a process to have multiple threads of execution thus allowing the process to perform more than one task at a time.
A thread, sometimes called a lightweight process (LWP), is a basic unit of CPU utilization; it comprises a thread ID, a program counter, a register set, and a stack. It shares with other threads belonging to the same process its code section, data section, and other operating-system resources, such as open files and signals. A traditional (or heavyweight) process has a single thread of control. If the process has multiple threads of control, it can do more than one task at a time.
Many software packages that run on modern desktop PCs are multithreaded. An application typically is implemented as a separate process with several threads of control.
Posted by charrie at 3:47 AM 0 comments
Labels: OS5
Kernel Thread
Kernel threads are supported directly by the operating system: The kernel performs thread creation, scheduling, and management in kernel space. Because thread management is done by the operating system, kernel threads are generally slower to create and manage than are user threads.
Posted by charrie at 3:45 AM 0 comments
Labels: OS5
User Thread
User threads are supported above the kernel and are implemented by a thread library at the user level. The library provides support for thread creation, scheduling, and management with no support from the kernel. Because the kernel is unaware of user-level threads, all thread creation and scheduling, are done in user space without the need for kernel intervention.
Posted by charrie at 3:44 AM 0 comments
Labels: OS5
Benefits of Multi - threading Programming
1. Responsiveness: Multithreading an interactive application may allow a program to continue running even if part of it is blocked or is performing a lengthy operation, thereby increasing responsiveness to the user.
2. Resource sharing: By default, threads share the memory and the resources of the process to which they belong. The benefit of code sharing is that it allows an application to have several different threads of activity all within the same address space.
3. Economy: Allocating memory and resources for process creation is costly. Alternatively, because threads share resources of the process to which they belong, it is more economical to create and context switch threads.
4. Utilization of multiprocessor architectures: The benefits of multithreading can be greatly increased in a multiprocessor architecture, where each thread may be running in parallel on a different processor. A single-threaded process can be only run on one CPU, no matter how many are available. Multithreading on a multi-CPU machine increases concurrency.
Posted by charrie at 3:41 AM 0 comments
Labels: OS5
Interprocess Communicatiom
Direct Communication - each process that wants to communicate must explicitly name the recipient or sender of the communication.
Indirect Communication - the messages are sent to and received from mailboxes, or ports.
Synchronization
- Blocking send - has the sender block until the message is received
- Nonblocking send - has the sender send the message and continue
- Blocking receive - has the receiver receive a valid message or null
- Nonblocking receive - has the receiver block until a message is available
Queue of messages attached to the link; implemented in one of three ways.
1. Zero capacity – 0 messages
Sender must wait for receiver (rendezvous).
2. Bounded capacity – finite length of n messages
Sender must wait if link full.
3. Unbounded capacity – infinite length
Sender never waits.
Producer- consumer 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.
Posted by charrie at 2:10 AM 0 comments
Labels: OS4
Thursday, July 16, 2009
Cooperating Processes
COOPERATING PROCESSES
The concurrent processes executing in the operating system may be either independent processes or cooperating processes.
- A process id independent if it cannot affect or be affected by the other processes executing in the system
- A process is cooperating if it can affect or be affected by the other processes executing in the system
There are several reasons for providing an environment that allows process cooperation
1. Information sharing - Since several users may be interested in the same piece of information (for instance, a shared file) we must provide an environment to allow concurrent access to these types of resources
2. Computation speedup - If we want a particular task to run faster, we must break it into subtasks, each of which will be executing in parallel with the others. Notice that such a speedup can be achieved only if the computer has multiple processing elements (such as CPU's or I/O channels)
3. Modularity - We may want to construct the system in a modular fashion, dividing the system function into processes.
4. Convenience - Even an individual user may have many tasks to work on at one time.� For instance, a user may be editing, printing, and compiling in parallel.
- A producer process produces information that is consumed by a consumer process.
- To allow producer and consumer processes to run concurrently we must have available a buffer of items that can be filled by the producer and emptied by the consumer
- The unbound-buffer producer-consumer problem places no practical limit on the size of the buffer.
- The bound-buffer producer-consumer problem assumes that there is a fixed buffer size
Posted by charrie at 3:55 AM 0 comments
Labels: OS4
Interprocess Communication
Since processes frequently needs to communicate with other processes therefore, there is a need for a well-structured communication, without using interrupts, among processes.
Race Conditions
In operating systems, processes that are working together share some common storage (main memory, file etc.) that each process can read and write. When two or more processes are reading or writing some shared data and the final result depends on who runs precisely when, are called race conditions. Concurrently executing threads that share data need to synchronize their operations and processing in order to avoid race condition on shared data. Only one ‘customer’ thread at a time should be allowed to examine and update the shared variable.Race conditions are also possible in Operating Systems. If the ready queue is implemented as a linked list and if the ready queue is being manipulated during the handling of an interrupt, then interrupts must be disabled to prevent another interrupt before the first one completes. If interrupts are not disabled than the linked list could become corrupt.
Posted by charrie at 3:21 AM 0 comments
Labels: OS4
Process Scheduling
1. Scheduling queue
- 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.
- Process migration between the various queues.
2. Schedulers
Goal – mimic functionality of kernel threads
gain performance of user space threads . Avoids unnecessary user/kernel transitions. Kernel assigns virtual processors to each process lets runtime system allocate threads to processors.
Problem: Fundamental reliance on kernel (lower layer)
calling procedures in user space (higher layer)
3. Context Switch -To give each process on a multiprogrammed machine a fair share of the CPU, a hardware clock generates interrupts periodically. This allows the operating system to schedule all processes in main memory (using scheduling algorithm) to run on the CPU at equal intervals. Each time a clock interrupt occurs, the interrupt handler checks how much time the current running process has used. If it has used up its entire time slice, then the CPU scheduling algorithm (in kernel) picks a different process to run. Each switch of the CPU from one process to another is called a context switch.
Major Steps of Context Switching :
- The values of the CPU registers are saved in the process table of the process that was running just before the clock interrupt occurred.
- The registers are loaded from the process picked by the CPU scheduler to run next.
In a multiprogrammed uniprocessor computing system, context switches occur frequently enough that all processes appear to be running concurrently. If a process has more than one thread, the Operating System can use the context switching technique to schedule the threads so they appear to execute in parallel. This is the case if threads are implemented at the kernel level. Threads can also be implemented entirely at the user level in run-time libraries. Since in this case no thread scheduling is provided by the Operating System, it is the responsibility of the programmer to yield the CPU frequently enough in each thread so all threads in the process can make progress.
Action of Kernel to Context Switch Among Threads
The threads share a lot of resources with other peer threads belonging to the same process. So a context switch among threads for the same process is easy. It involves switch of register set, the program counter and the stack. It is relatively easy for the kernel to accomplished this task.
Action of kernel to Context Switch Among Processes
Context switches among processes are expensive. Before a process can be switched its process control block (PCB) must be saved by the operating system. The PCB consists of the following information:
- The process state.
- The program counter, PC.
- The values of the different registers.
- The CPU scheduling information for the process.
- Memory management information regarding the process.
- Possible accounting information for this process.
- I/O status information of the process.
- When the PCB of the currently executing process is saved the operating system loads the
- PCB of the next process that has to be run on CPU. This is a heavy task and it takes a lot of time.
Posted by charrie at 2:17 AM 0 comments
Labels: OS4
Operations on Processes
- Process Creation -Principal events that cause process creation . System initialization. Execution of a process creation system . User request to create a new process . Initiation of a batch job.
- Process Termination - Conditions which terminate processes . Normal exit (voluntary) . Error exit (voluntary) . Fatal error (involuntary) . Killed by another process (involuntary)
Posted by charrie at 2:11 AM 0 comments
Labels: OS4
The Concepts of Process
A.) Process State - consist of everything necessary to resume the process execution if it is somehow put aside temporarily.
The process state consists of at least following:
- Code for the program.
- Program's static data.
- Program's dynamic data.
- Program's procedure call stack.
- Contents of general purpose registers.
- Contents of program counter (PC)
- Contents of program status word (PSW).
- Operating Systems resource in use.
A process goes through a series of discrete process states.
- New State: The process being created.
- Running State: A process is said to be running if it has the CPU, that is, process actually using the CPU at that particular instant.
- Blocked (or waiting) State: A process is said to be blocked if it is waiting for some event to happen such that as an I/O completion before it can proceed. Note that a process is unable to run until some external event happens.
- Ready State: A process is said to be ready if it use a CPU if one were available. A ready state process is runable but temporarily stopped running to let another process run.
- Terminated state: The process has finished execution.
B.) Process Control Block - all of the information needed to keep track of a process when switching is kept in a data package. A Process Control Block (PCB, also called Task Control Block or Task Struct) is a data structure in the operating system kernel containing the information needed to manage a particular process. The PCB is "the manifestation of a process in an operating system". The process control block typically contains:
- An ID number that identifies the process (Process Identifier)
- Pointers to the locations in the program and its data where processing last occurred .
- Register contents .
- States of various flags and switches .
- Pointers to the upper and lower bounds of the memory required for the process .
- A list of files opened by the process .
- The priority of the process .
- The status of all I/O devices needed by the process
Each process has a status associated with it. Many processes consume no CPU time until they get some sort of input. For example, a process might be waiting for a keystroke from the user. While it is waiting for the keystroke, it uses no CPU time. While it's waiting, it is "suspended". When the keystroke arrives, the OS changes its status. When the status of the process changes, from pending to active, for example, or from suspended to running, the information in the process control block must be used like the data in any other program to direct execution of the task- switching portion of the operating system. This process swapping happens without direct user interference, and each process gets enough CPU cycles to accomplish its task in a reasonable amount of time. Trouble can begin if the user tries to have too many processes functioning at the same time. The operating system itself requires some CPU cycles to perform the saving and swapping of all the registers, queues and stacks of the application processes. If enough processes are started, and if the operating system hasn't been carefully designed, the system can begin to use the vast majority of its available
C.) Threads - which defines a sequential execution stream within a process. A thread is bound to a single process / address space .
Thread types :
User threads - thread management done by user-level threads library. Kernel does not know about these threads
Kernel threads - Supported by the Kernel and so more overhead than user threads .
Posted by charrie at 1:45 AM 0 comments
Labels: OS4
Thursday, July 9, 2009
Quiz #3
1. What are the major activities of an Operating System with regards to process management?
The Operating System is responsible for the following activities in connection with process management:
- Process creation an deletion.
- Process suspension and resumption.
- Provision of mechanisms for: process synchronization, process communication, deadlock handling
2. What are the major activities of an Operating System with regards to main memory management?
The following are some of the activities in connections with memory managemen that are handled by Operating System:
- Keep track of which parts of memory are currently being used and by whom
- Decide which processes to load when memory space becomes available.
- Allocate and deallocate memory space as needed.
3. What are the major activities of an Operating System with regards to secondary storage management?
The Operating System is responsible for the following activities in connection with disk management:
- Free space management.
- Storage allocation.
- Disk scheduling.
4. What are the major activities of an Operating System with regards to file management?
The Operating System is responsible for the following activities in connection with file management:
- File creation and deletion.
- Directory creation and deletion.
- Support of primitives for manipulating files and directories.
- Mapping files into secondary storage.
- File backup on stable (nonvolatile) storage media.
5. What is the purpose of the command interpreter?
Serves as the interface between the user and the Operating System
- User friendly, mouse based windows environment in the Macintosh and in Microsoft Windows.
- In MS-DOS and UNIX, commands are typed on a keyboard and displayed on a screen or pronting terminal with the Enter ot Return key indicating that a command is compplete and ready to be executed.
Many commands are given to the Operating Sysytem by control statements which deal with:
- process creation and mangement
- I/O handling
- secondary-storage management
- main-memory management
- file-system access
- protection
- networking
Posted by charrie at 3:58 AM 0 comments
Labels: Quiz
Tuesday, July 7, 2009
Operating System Structure
Virtual Machine
- Implementation - However, the Java virtual machine does not assume any particular implementation technology, host hardware, or host operating system.
A virtual machine implementation can use annotation information to load and run a computer program more efficiently. - Benefits - A virtual machine, simply put, is a virtual computer running on a physical computer. The virtual machine emulates a physical machine in software. This includes not only the processor but the instruction set, the memory bus, any BIOS commands and critical machine hardware such as the system clock and and DMA hardware. Depending upon the machine peripheral devices are generally virtualized including storage devices like floppy drives, hard drives and CD drives. Video, keyboard and mouse support are also common. A virtual machine must look and act just like the real thing so standard software, like operating systems and applications, can run without modification. IT departments have already found the benefits of running virtual servers over having multiple physical servers. Development and testing share many of the same benefits. Virtualization has become a buzzword in the industry. Windows is becoming more virtualized so even if you aren't using virtual machines today you may be in the future.
System Generation
System generation called also installing and implementing. System definition is sometimes called design. System restart is the component that uses the results of a system generation to place the system in a condition to process real-time input. The initial startup is a special case of restart and for this reason system restart is sometimes called initial program load, or IPL. System restart uses values found in tables set up during system generation and changed during the online execution of the system. A switchover implies shifting the processing load to a different central processing complex (CPC), and requires some additional procedures on the part of a system operator. A restart or switchover may be necessary either for a detected hardware failure, detected software failure, or operator option. In any event, system definition (design), initialization, restart, and switchover are related to error recovery. This provides the necessary background to use this information, which is the principal reference to be used to install the z/TPF system.
Performing a system generation requires a knowledge of the z/TPF system structure, system tables, and system conventions, a knowledge of the applications that will be programmed to run under the system, and a user's knowledge of z/OS. Knowledge of the z/TPF system, Linux, and the application are required to make intelligent decisions to accomplish the system definition of a unique z/TPF system environment. The use of z/OS and Linux is necessary because many programs used to perform system generation run under control of z/OS or Linux. Although this information does not rely on much z/OS or Linux knowledge, when the moment arrives to use the implementation information, the necessary z/OS and Linux knowledge must be acquired. You are assumed to have some knowledge of the S/370 assembly program as well as jargon associated with the z/OS and Linux operating systems. Some knowledge of C language is also helpful, because some of the programs that are used to generate the system are written in C.
System Boot
The typical computer system boots over and over again with no problems, starting the computer's operating system (OS) and identifying its hardware and software components that all work together to provide the user with the complete computing experience. But what happens between the time that the user powers up the computer and when the GUI icons appear on the desktop?
In order for a computer to successfully boot, its BIOS, operating system and hardware components must all be working properly; failure of any one of these three elements will likely result in a failed boot sequence.
When the computer's power is first turned on, the CPU initializes itself, which is triggered by a series of clock ticks generated by the system clock. Part of the CPU's initialization is to look to the system's ROM BIOS for its first instruction in the startup program. The ROM BIOS stores the first instruction, which is the instruction to run the power-on self test (POST), in a predetermined memory address. POST begins by checking the BIOS chip and then tests CMOS RAM. If the POST does not detect a battery failure, it then continues to initialize the CPU, checking the inventoried hardware devices (such as the video card), secondary storage devices, such as hard drives and floppy drives, ports and other hardware devices, such as the keyboard and mouse, to ensure they are functioning properly.
Once the POST has determined that all components are functioning properly and the CPU has successfully initialized, the BIOS looks for an OS to load.
The BIOS typically looks to the CMOS chip to tell it where to find the OS, and in most PCs, the OS loads from the C drive on the hard drive even though the BIOS has the capability to load the OS from a floppy disk, CD or ZIP drive. The order of drives that the CMOS looks to in order to locate the OS is called the boot sequence, which can be changed by altering the CMOS setup. Looking to the appropriate boot drive, the BIOS will first encounter the boot record, which tells it where to find the beginning of the OS and the subsequent program file that will initialize the OS.
Once the OS initializes, the BIOS copies its files into memory and the OS basically takes over control of the boot process. Now in control, the OS performs another inventory of the system's memory and memory availability (which the BIOS already checked) and loads the device drivers that it needs to control the peripheral devices, such as a printer, scanner, optical drive, mouse and keyboard. This is the final stage in the boot process, after which the user can access the system’s applications to perform tasks.
Posted by charrie at 2:55 AM 0 comments
