Welcome to my Blogsite!

http://www.blogsite.psvphil.com

http://aurelie.prepys.com

http://www.ideas.perfectkeys.com

LECTURE 4

Operating Systems - Process Management (Night Class)

By Aurelie A. Peralta

Process Management

A process can be thought of as a program in execution. A process will need certain resources - such as CPU time, memory, files, and I/O devices - to accomplish its task. These resources are allocated to the process either when it is created or while its executing. A process is the unit of work in most systems. Such a system consists of a collection of processes: Operating-system processes execute system code, and user processes execute user code. All these may execute concurrently. Although traditionally a process contained only a single thread of control as it ran, most modern operating systems now support processes that have multiple threads.

Processes

Process Concept

A batch system executes jobs, whereas a time-shared system has user programs, or tasks. All these activities are similar, so we call all of them processes.

The Process

Informally, a process is a program in execution. A process is more than the program code, which is sometimes known as the text section. It also includes the current activity, as represented by the value of the program counter and the contents of the processor’s registers. It generally include the process stack, which contains temporary data, and a data section, which contains global variables.

Process State

As process executes, it changes state. The state of the process is defined in part by the current activity of the process. Each process may be in one of the following states:

1. New: The process is being created.

2. Running: Instructions are being executed.

3. Waiting: The process is waiting for some event to occur.

4. Ready: The process is waiting to be assigned to a processor.

5. Terminated: The process has finished execution.

Process Control Block

Each process is represented in the operating system by a process control block (PCB) - also called a task control block. The PCB simply serves as the repository for any information that may vary from process to process. It contains many pieces of information associated with a specific process, including these:

1. Process State

2. Program Counter: The counter indicates the address of the next instruction to be executed for this process.

3. CPU Registers: They include accumulators, index registers, stack pointers, and general-purpose registers, plus any condition-code information.

4. CPU-scheduling information: Includes process priority, pointers to scheduling queues, and any other scheduling parameters.

5. Memory-management information: This information may include such information as the value of the base and limit registers, the page tables, or the segment tables, depending on the memory system used by the operating system.

6. Accounting information: This information includes the amount of CPU and the real time used, time limits, account numbers, job or process numbers, and so on.

7. I/O status information: Includes the list of I/O devices allocated to this process, a list of open files, and so on.

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.

Process Scheduling

The objective of multiprogramming is to have some process running at all times, so as to maximize CPU utilization. The objective of time-sharing is to switch the CPU among processes so frequently that users can interact with each program while it is running. A uniprocessor systems can have only one running process. If more processes exist, the rest must wait until the CPU is free and can be rescheduled.

Scheduling Queues

1. Job queue - consists of all processes in the system.

2. Ready queue - keeps the processes that are residing in main memory and are ready and waiting to be executed.

3. Device queue - the list of processes waiting for a particular I/O device.

Queueing diagram - a common representation of process scheduling.

Schedulers

A process migrates between the various scheduling queues throughout its lifetime. The operating system must select, for scheduling purposes, processes from these queues in some fashion. The selection process is carried out by the appropriate scheduler.

Context Switch

Switching the CPU to another process requires saving the state of the old process and loading the saved state for the new process. This task is known as a context switch.

Operations on Processes

The processes in the system can execute concurrently, and they must be created and deleted dynamically. Thus, the operating system must provide a mechanism or facility for process creation and termination.

Process Creation

A process may create several new processes, via a create-process system call, during the course of execution. The creating process is called a parent process, whereas the new processes are called the children of that process. Each of these new processes may in turn create other processes, forming a tree of processes.

Process Termination

A process terminates when it finishes executing its final statement and asks the operating system to delete it by using the exit system call. At that point, the process may return data (output) to its parent process (via the wait system call). All the resources of the process - including physical and virtual memory, open files, and I/O buffers - are deallocated by the operating system. Termination occurs under additional circumstances. A process can cause the termination of another process via an appropriate system call.

Cooperating Processes

A process is independent if it cannot affect or be affected by the other resources executing in the system. Clearly, any process that does not share any data with any other process is independent. On the other hand, a process is cooperating if it can affect or be affected by the other processes executing in the system. Clearly, any process that shares data with other processes is a cooperating process.

We may want to provide an environment that allows process cooperation for several reasons:

1. Information sharing

2. Computation speedup

3. Modularity

4. Convenience

Interprocess Communication

Interprocess Communication facility (IPC) provides mechanism to allow processes to communicate and to synchronize their actions without sharing the same address space. IPC is particularly useful in distributed environment where the communicating processes may reside on different computers connected with a network. IPC is best provided by a message-passing system.

Message-Passing System

The function of a message system is to allow processes to communicate with one another without the need to resort to shared data. Here are several methods for logically implementing a link and the send-receive operations:

1. Direct or indirect communication

2. Symmetric or asymmetric communication

3. Automatic or explicit buffering

4. Send by copy or send by reference

5. Fixed-sized or variable-size messages

Naming

Processes that want to communicate must have a way to refer to each other.

Direct and Indirect Communication

With direct communication, each process that wants to communicate must explicitly name the recipient or sender of the communication. With indirect communication, the messages are sent to and received from mailboxes, or ports. A mailbox can be viewed abstractly as an object into which messages can be placed by processes and from which messages can be placed by processes and from which messages can be removed. Each mailbox has a unique identification.

Synchronization

Communication between processes takes place by calls to send and receive primitives. There are different design options for implementing each primitive. Message passing may be either blocking or nonblocking - also known as synchronous and asynchronous .

Buffering

Whether communication is direct or indirect, messages exchanged by communicating processes reside in a temporary queue. Basically, such a queue can be implemented in three ways:

1. Zero capacity

2. Bounded capacity

3. Unbounded capacity

Communication in Client-Server Systems

Sockets

A socket is defined as an endpoint for communication. A pair of processes communicating over a network employs a pair of sockets - one for each process. A socket is made up of an IP address concatenated with a port number. In general, sockets use a client-server architecture.

Remote Procedure Calls

One of the most common forms of remove service is the RPC paradigm. RPC was designed as a way to abstract the procedure-call mechanism for use between systems with network connections. In contrast to IPC facility, the messages exchanged for RPC communication are well structured and are thus no longer just packets of data.

A port is simply a number included at the start of a message packet. Whereas a system normally has one network address, it can have many ports within that address to differentiate the many network services it supports.

Remote Method Invocation

The remote method invocation (RMI) is a Java feature similar to RPCs. RMI allows a thread to invoke a method on a remote object. Objects are considered remote if they reside in a different Java Virtual Machine.

Threads

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.

Benefits of Multithreaded programming can be broken down into four major categories:

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.

User and Kernel Threads

Support for threads may be provided at either the user level, for user threads, or by the kernel, for kernel threads.

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.

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.

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.

Thread cancellation is the task of terminating a thread before it has completed. A thread that is to be cancelled is often referred to as the target thread. Cancellation of a target thread may occur in two different scenarios:

1. Asynchronous cancellation: One thread immediately terminates the target thread.

2. Deferred cancellation: The target thread can periodically check if it should terminate, allowing the target thread an opportunity to terminate itself in an orderly fashion.

Pthreads refers to the POSIX standard defining an API for thread creation and synchronization. This is a specification for thread behavior, not an implementation. Operating system designers may implement the specification in any way they wish. Generally, libraries implementing the Pthreads specification are restricted to UNIX-based systems such as Solaris 2. The Windows operating systems have generally not supported Pthreads, although shareware versions are available in the public domain.

A thread is a flow of control within a process. A multithreaded process contains several different flows of control within the same address space. User-level threads are threads that are visible to the programmer and are unknown to the kernel. A thread library in user space typically manages user-level threads.

CPU Scheduling

CPU scheduling is the basis of multiprogrammed operating systems. By switching the CPU among processes, the operating system can make the computer more productive.

Basic Concepts

The objective of multiprogramming is to have some process running at all times, in order to maximize CPU utilization. In a uniprocessor system, only one process may run at a time; any other processes must wait until the CPU is free and can be rescheduled.

Scheduling is a fundamental operating-system function. Almost all computer resources are scheduled before use. The CPU is, of course, one of the primary computer resources. Thus, its scheduling is central to operating-system design.

Reference: Operating System Concepts by Silberschatz, Galvin, and Gagne, 2003