AOS Assignment

AOS Solutions for Unit 1 and 2

UNIT-1 DEC – 2011

1a. Describe the essential properties of following types of Operating Systems: 1)Time Sharing 2)Embedded Systems.

Ans:

Time Sharing Systems support multiple interactive users rather than the user preparing a job for execution ahead of time, the user establishes an interactive session with the computer and then provides commands, programs and data as they are needed during the session.

It uses multiprogramming.

It support interactive computing model (Illusion of multiple consoles).

It provides different scheduling & memory allocation strategies than batch.

It tends to propagate processes.

It gives considerable attention to resource isolation (security & protection).

It tends to optimize response time.

Figure 1a : Time Sharing Systems

Embedded systemswere originally used to control autonomous systems such as hydrolic dams, satellites. The OS is usually required to guarantee response times for particular computing tasks.

The computer is dedicated to a single purpose

It is classic embedded system.

It must give respond to external stimuli in fixed time

These are continuous media popularizing real-time techniques

1b. Difference between the Space Multiplexing and Time Multiplexing. Give two examples.

Ans:

Space Multiplexing

In Space Multiplexing a resource is divided into two or more distinct units and then the individual parts are allocated to process.

Eg 1: A complex of condominiums is space multiplexed by dividing the building into a collection of condos then allocating each condo to a different occupant.

Eg 2: In city bus many people share the bus by occupying one seat.

Time Multiplexing

In Time multiplexing a resource is not divided instead one process can use the entire resource for a period of time and then another process uses it at a later time.

Eg 1: A metered automobile parking space is shared in time sharing manner using time multiplexing technique.

Eg 2: In computer systems all processes share the physical processor in time multiplexed manner.

Figure 1b : Time Sharing Systems

1c. What are the distinctions among window NT ,windows 2000 and windows XP?

Ans:

Windows XP uses the same windows NT code base. Along with code from windows98.

Windows NT will refer any version of the operating systems built from the windows NT code base including 2000 and XP.

Windows NT is a flagship windows OS family. Its windows NT executive and win32 subsystems implement all functions on the win32 API.

It is the most complex member of the OS family.

Figure 1c : Windows NT, 98, 2000

1d. What are the benefits of Batch Systems ?

The following are the benefits of batch Systems

  • Provides multiprogramming
  • Job (file of OS commands) prepared offline
  • Batch of jobs given to OS at one time
  • OS processes jobs one-after-the-other
  • No human-computer interaction
  • OS optimizes resource utilization
  • Batch processing (as an option) still used today

Figure 1d : Batch Systems

JUNE- 2012

1.a Define with an example, the concept of multiprogramming and multiprocessing system. Discuss the advantages of multiprocessing systems.

The abstract machine for one process used the physical processor for a fraction of a second, and then the OS time-multiplexes the processor to a different abstract machine. Meanwhile the computer’s memory is shared using space-multiplexing. This technique of sharing the processor to execute different processes is called multiprogramming.

In the above Figure 1b, there are N different abstract machines (named Pi,Pj.....Pk) . The OS divides the physical memory into N different blocks, and then allocates a block to each abstract machine. When the program for Pi is loaded into its block of memory, it can then share the processor using time multiplexed sharing. Over a time period equal to N time slices,each Pi uses the processor for only one time slice, but it occupies its block of memory for future use.

The below Figure 1e shows there are three cars to be cleaned. The complete operation requires that the cars to be washed, dried and the inside vacuumed. The car wash coordinator schedules the work so that the car 1 is being washed at the same time as car 2 being vacuumed, while car 3 is waiting. Now, when the car 1 has been washed, it is then dried. At the same time, car 2 will be washed and car 3 vacuumed. When car 1 has been dried, it is vacuumed at the same time that car 2 is dried and car 3 is washed. As soon as car 1 has been vacuumed, and car 2 has been dried, they are both finished. This operation is called “sequential car wash”.

Figure 1e : Multiprogramming

The same idea can be applied to processes. The characteristics of process execution are that support parallelisms are

• In modern computers, IO operations take more time to complete than processor operations.

• The process, Pi does not the processor while it doing IO.

• Each of Pi spends most of its time using the IO devices in hardware.(Figure 1f a below)

• In a conventional computer, there are multiple devices but only one processor.

Suppose the OS controls the processor usage so whenever Pi is involved in IO, some other process Pi, uses the processor as shown in Figure1fb. Then achieve the true parallelism by having processes simultaneously using different parts of the computer.

Advantages of Multiprocessing:

  • At the same time two or more process can be executed simultaneously. So no extra time is required.
  • Maximizes Resource Utilization, hence increases Performance of the system.

Figure 1f : Multiprogramming Processor Usage

1b. Explain various OS strategies involved from user perspective for development of i) Batch processing ii)Personal Computers and work stations.

The various operating systems strategies are as follows

i) Batch processing

A batch processing system services individual jobs from a predefined collection of jobs. Each batch job is specified by a predefined list of OS commands called job control specification. Once an OS begins to execute a job, it executes all commands in the list in sequence. Users have no opportunity to interact with an executing job.

From user’s perspective, the job control specification defines all the requests necessary for the OS to perform an information processing task. For example, if the job is to produce a corporation’s monthly invoices, the OS may have to execute a suite of program executions to produce the invoices: one process to accumulate sales in each division, another process to determine the invoice amounts, a third process to update the company accounts payable information, and so on.

These programs operate on information contained in files rather than information supplied by an interactive user so there is no need for human interaction with the job while it is running. Each user prepares a job and den the jobs are collected into batch and submitted to the computer. After the computer has finished executing that batch, it produces output listings. The output listing is given to user to reflect the result of running their job.

JOjj

Input spool Output spool

Figure- Batch processing System

An input spooler groups jobs into a batch, then sends the batch to the computer. As the computer completes jobs, it writes each job’s output to output spool. The output spool is printed and the job results are returned to the end user.

ii) Personal Computers and work stations.

Personal computer system software was generally designed to allow one user to execute one program at a time but no multiprogramming. Because there was no multiprogramming, there was no requirement for resource isolation or sharing.

The primary requirement for the system software was to provide hardware abstraction. Both Apple and IBM stored their abstraction software in ROMs that is it would always be present when machine was powered up.

The work station was distinctly different from personal computer .Workstations are configured with enough resources that it made sense to use timesharing OS technology, especially multiprogramming for their OS.Almost all workstations eventually used some from UNIX.

Personal computers and workstations gave users new freedom in computing, which changed the way people perceived the computer. Rather than viewing it as an ominous corporate resource, people began to think of list of tools for accomplishing everyday work, similar to telephone, typewriter pr photocopier. As personal productivity tools such oas word processors, desktop publishing systems, spreadsheets and the personal databases evolved, the single –user computer became deeply entrenched in corporations.

UNIT -2 DEC-2011

2(a) . Write a unix program that create a child process that prints a greeting ,sleep for 20 second and then exit .the parent process should print a greeting before creating the child and another after the child terminated. It should then terminated?

#include<sys/wait.h>

#include<stdio.h>

#include<stdlib.h>

int main()

{

int child;

printf("Parent Greeting\n");

child = fork();

if(child >=0)

{

if(child ==0)

{ printf("Child process\n");

sleep(2);

printf("Child exiting\n");

exit(0);

}

}

else

{

printf("Failed\n");

}

printf("End");

exit(1);

return0;

}

2(b). Explain the difference b/w the fork(),join() and quit() system calls with code fragment?

System callfork()is used to create processes. It takes no arguments and returns a process ID. The purpose offork()is to create anewprocess, which becomes thechildprocess of the caller. After a new child process is created,bothprocesses will execute the next instruction following thefork()system call. Therefore, we have to distinguish the parent from the child. This can be done by testing the returned value offork():

  • Iffork()returns a negative value, the creation of a child process was unsuccessful.
  • fork()returns a zero to the newly created child process.
  • fork()returns a positive value, theprocess IDof the child process, to the parent. The returned process ID is of typepid_tdefined insys/types.h. Normally, the process ID is an integer. Moreover, a process can use functiongetpid()to retrieve the process ID assigned to this process.

Therefore, after the system call tofork(), a simple test can tell which process is the child.

L0:count1=2;

Count2=2;

<compute a1>

Update(x);

Fork(L2);

<compute A2>

L1:join(count1);

Retrieve(y);

Join(count2);

Goto L0;

L2:retrieve(x);

<compute B1>;

Update(y);

Fork(L3);

Goto L0;

L3:<compute B2>

Join(count2);

Goto L0;

Join() operation is used to join two different groups of codes.

Quit() is used by the process to terminate itself. The command destroys the calling process

2(c).Write a program to create a thread using pthread/javathread?

class MyThread extends Thread {

public MyThread (String s) {

super(s);

}

public void run() {

System.out.println("Run: "+ getName());

}

}

class TestThread {

public static void main (String arg[]) {

Scanner input = new Scanner(System.in);

System.out.println("Please input the number of Threads you want to create: ");

int n = input.nextInt();

System.out.println("You selected " + n + " Threads");

for (int x=0; x<n; x++)

{

MyThread temp= new MyThread("Thread #" + x);

temp.start();

System.out.println("Started Thread:" + x);

}

}

#include<pthread.h>
#include<stdio.h>
void*hello(void*simpleInt)
{
intsimple;
simple = (int)simpleInt;
printf(&quot;Hello From Thread ! I got fed with an integer whose value is %ld!\n&quot;, simple);
pthread_exit(NULL);
}
intmain (intargc,char*argv[])
{
pthread_tthread;
intrc;
intnumber = 3;
rc = pthread_create(&amp;thread, NULL, hello, (void*)number);
pthread_exit(NULL);
}

2.(d)With a neat diagram explain process with multiple threads?

The term “process” has two different meanings because of technology evolution. First, the classic process represents the concept of a program in execution on a Von Neumann computer. Second , the modern process corresponds to the part of a classic process that defines a customized computational framework in which a program executes.

The thread is a part of a classic process that keep track of code execution within that framework.

In the classic process case, the multiprogramming abstract machine is a model of the physical CPU and memory. Only one entity can be executing in an abstract machine and the implicit single thread also called base thread associated with a classic process. When the abstract machine processor is running , the base thread is running. When the abstract processor is halted, the base thread is suspended.

In the modern process case, the abstract machine allows additional threads to share the host process’s resources such as the abstract processor and memory. This can be done by another abstraction leap as shown in a figure.

In figure, the idea is for threads to be time-multiplexed on top of the abstract machine. If we really implemented threads, it would mean that each abstract machine would include its own multiprogramming OS. This is essentially how user space thread packages such as the Mach C threads and POSIX threads libraries implement modern processes and threads. Modern operating systems provide explicit OS support for the thread model.

JUNE -2012

2.(a) Differentiate between windows NT,windows 95 and windows CE?

Windows 95 integrated Microsoft's formerly separateMS-DOSandWindowsproducts. It featured significant improvements over its predecessor,Windows 3.1, most notably in the graphical user interface (GUI) and in its relatively simplified "plug-n-play" features. There were also major changes made at lower levels of the operating system, such as moving from a mainly16-bit architectureto apre-emptivelymultitasked32-bit architecture.

Accompanied by an extensive marketing campaign, Windows 95 was a major success in the marketplace at launch and shortly became the most popular desktop operating system. It also introduced numerous functions and features that were featured in later Windows versions, such as the taskbar, the 'Start' button, and the way the user navigates. It was also suggested that Windows 95 had an effect of driving other major players (includingOS/2) out of business, something which would later beused in courtagainst Microsoft.

Windows 95 was designed to be maximally compatible with existingMS-DOSand 16-bit Windows applications anddevice drivers, while under this constraint offering a more stable and better performing system.

Windows CE is optimized for devices that have minimal storage; a Windows CE kernel may run in under a megabyte of memory. Devices are often configured withoutdisk storage, and may be configured as a "closed" system that does not allow for end-user extension (for instance, it can be burned intoROM). Windows CE conforms to the definition of areal-time operating system, with a deterministic interrupt latency. From Version3 and onward, the system supports 256priority levelsand usespriority inheritancefor dealing withpriority inversion. The fundamental unit of execution is thethread. This helps to simplify the interface and improve execution time.

Windows NT was hardware and software portability. Various versions of NT family operating systems have been released for a variety of processor architectures, initially IntelIA-32,MIPSR3000/R4000, andAlpha, withPowerPC,Itanium,AMD64andARMsupported in later releases. The idea was to have a common code base with a custom Hardware Abstraction Layer(HAL) for each platform. However, support for MIPS, Alpha, and PowerPC was later dropped after NT 4.0. Broad software compatibility was achieved with support for severalAPI"personalities", includingWin32,POSIX, andOS/2APIs - the latter two were phased out starting with Windows XP.PartialMS-DOScompatibility was achieved via an integratedDOS Virtual Machine- although this feature is being phased out in thex86-64architecture.NT supported per-object (file, function, and role)access control listsallowing a rich set of security permissions to be applied to systems and services. NT supported Windows network protocols, inheriting the previous OS/2LAN Managernetworking, as well asTCP/IPnetworking (for which Microsoft would implement a TCP/IP stack derived at first fromSTREAMS, then later rewritten in-house.

2(b) Define and list out in details the difference between a thread and a process. Explain with an example the concert of sequential and multithreaded computation along with their advantages and disadvantages?

Threads

Will by default share memory.

Will share file descriptors.

Will share file system context.

Will share signal handling.

Processes

Will by default not share memory.

Most file descriptors not shared.

Don't share file system context.

Don't share signal handling.

Processes

Process (slightly oversimplified): "An execution stream in the context of a particular process state."

Execution stream: a sequence of instructions (only one thing happens at a time).

Process state: everything that can affect, or be affected by, the process: code, data, call stack, open files, network connections, etc.

Is a process the same as a program?

Uniprogramming system: only supports a single process. Simplifies some parts of OS, but many other things are hard to do.

Some early personal computer operating systems were uniprogramming (e.g. MS-DOS), but these systems are almost unheard of today.

This is not called "uniprocessing": that refers to a system with only one processor.

Virtually all modern operating systems aremultiprogramming systems: multiple processes can exist simultaneously and share the machine.

Threads

Most modern operating systems also support threads: multiple execution streams within a single process

Threads share process state such as memory, open files, etc.

Each thread has a separate stack for procedure calls (in shared memory)

Thread is unit of sequential execution

Why support threads?

Concurrent execution on multiprocessors

Manage I/O more efficiently: some threads wait for I/O while others compute

Most common usage for threads: large server applications

2.(c) With a neat diagram, explain the working of a modern operating system

Modern operating system evolved from all of the system: batch, timesharing ,personal computer and workstation software,embedded system,small computer and operating system for network(see fig).They inherited multiprogramming technology from batch andTimesharing system.While protection and security first in batch system,both developed rapidly timesharing environment.Human –computer interaction technology became issue with timesharing system,and continues to grow in importance with SSCs.The trend was accelerated with the dedicated memory and processors offered with personal computer and workstations.User began to demand windows and other visually oriented technologies.The client-server network programming model evolved from systems that supported network communication.Embedded systems have influenced real-time management,synchronization approaches,scheduling,and data in modern operating systems.