Anda di halaman 1dari 47

MULTIPROCESSOR OPERATING SYSTEMS PROGRAM 1 Semaphores - Multiprocessor operating systems Assume there are three processes: Pa, Pb,

, and Pc. Only Pa can output the letter A, Pb B, and Pc C. Utilizing only semaphores (and no other variables) the processes are synchronized so that the output satisfies the following conditions: a) A B must be output before any C's can be output. b) B's and C's must alternate in the output string, that is, after the first B is output, another B cannot be output until a C is output. Similarly, once a C is output, another C cannot be output until a B is output. c) The total number of B's and C's which have been output at any given point in the output string cannot exceed the number of A's which have been output up to that point. Examples AACB -- invalid, violates a) ABACAC -- invalid, violates b) AABCABC -- invalid, violates c) AABCAAABC -- valid AAAABCBC -- valid AB -- valid

AIM: semaphores. ALGORI THM: Step 1: Start the program.

Step 2: Declare the variables for more than two processes. Step 3: Declare the entry section for P1 and entry section for P2. Step 4: Define Q1:=TRUE and Q2:=TRUE.

Step 5: Assign TURN:=1 and TURN:=2. Step 6: Wait while Q2 of TURN:=1 and wait while Q1 of TURN:=2. Step 7: The processes are synchronized, so that output displayed in the order ABC. Step 8: Exit from section for P1 and exit section for P2 while Q1! =FALSE and Q2:=FALSE. Step 9: Bs and Cs must be alternate in the output String i.e) after the first B is displayed, another B cannot be the displayed until a C is displayed. Step 10: Similarly, once C is displayed, another C cannot be displayed until a B is displayed. Step 11: The total number of Bs and Cs which have been displayed at any given point in the output string cannot exceed. Step 12: Utilize only semaphores, the processes are synchronized so that the output is satisfied. Step 13: Execute the program.

PROGRA M: ABCs.java import java.io.Serializable; import java.util.Date; import java.util.Random; class BinarySemaphore {

class CountingSemaphore {

} class Pa extends ABCs implements Runnable { // extend ABCs to // access semaphore sum

} class Pb extends ABCs implements Runnable {

} class Pc extends ABCs implements Runnable {

} class ABCs {

= new BinarySemaphore(1); // Pa, Pb, protected static final CountingSemaphore sum // and Pc share = new CountingSemaphore(0); // them private static final long startTime = System.currentTimeMillis(); protected static final long age() { } private static final Random rnd = new Random(); protected static final double random() { } protected static final double random(int ub) { } protected static final void P(BinarySemaphore s) { } protected static final void V(BinarySemaphore s) { } protected static final void P(CountingSemaphore s) { } protected static final void V(CountingSemaphore s) { } protected static final int nap(int napTimeMS) {

OUTPUT: D:\Java\jdk1.6.0\bin>javac ABCs.java D:\Java\jdk1.6.0\bin>java ABCs

ABACABACABACAAABCABACBACABACABACABACABACABACABACAAAABC AAABCABCAA

RESULT:

semaphores is written and the output is executed successfully.

PROGRAM 2 Multithreading - Multiprocessor operating systems The Cigarette Smokers Problem smoker continuously makes a cigarette and smokes it. But to make a cigarette, a smoker needs three ingredients: tobacco, paper, and matches. One of the smoker threads has only paper, another has only tobacco, and the third has only matches. The agent thread has an infinite supply of all three materials. The three smoker threads are initially blocked. The agent places two randomly chosen (different) ingredients on the table and unblocks the one smoker who has the remaining ingredient. The agent then blocks. The unblocked smoker removes the two ingredients from the table, makes a cigarette, and smokes it for a random amount of time, unblocking the agent on completion of smoking the cigarette. The agent then puts out another random two of the three ingredients, and the cycle repeats. synchronize the agent thread and the three smoker threads. Do not mechanically translate semaphore code into monitor code! The agent thread executes in an agent object created from an agent class. Each smoker thread executes in a smoker object. All smoker objects are created from one smoker class whose constructor is used to specify the ingredient possessed by the smoker object. A driver class with a main method constructs the objects and starts the threads. Use a single monitor object instantiated from a class Control for synchronization. Each of the four threads invokes a synchronized monitor method for its synchronization. No semaphores are allowed. No synchronized blocks are allowed, only synchronized methods. No busy waiting is allowed. No calls to nap inside a synchronized method are allowed (do not nap while holding the monitor object's lock, that is,

while inside a synchronized method or while inside a method called by a synchronized method).

AIM: synchronize the agents thread and three smokers thread. ALGORI THM: Step 1: Start the Program. Step 2: Declare the variables to define agent and smoker and its needs.

Step 3: do forever {

Step 4: if (randNum==1) {

Step 5: Else if(randNum==2) {

Step 6: Else {

Step 7: In smokers code and other analgus do forever{

Step 8: Use a single monitor object instantiated from a class control for synchronization. No smokers, semaphores, synchronized blocks are allowed, allows only Synchronized methods. Step 9: No smokers semaphores, synchronized blocks are allowed allows only synchronized methods. Step 10: No class to map inside a synchronized methods are allowed. Step 11: Each smoker thread has only thing to include inhale cigarette. Step 12: But three smokers threads are initially blocked. The agent places two randomly chosen ingredients on the table and unblocks the smoker who has remaining ingredients agents then block

Step 13: Execute the Program.

PROGRA M: Agent.java import java.util.*; public class Agent extends Thread {

} Smoker .java import java.util.*; public class Smoker extends Thread {

} Table.java import java.util.*; public class Table { public static final int Nothing=0; public static final int Tobacco=1; public static final int Paper=2; public static final int Matches=4; public static final int Tobacco_Paper=Tobacco+Paper; public static final int Paper_Matches=Paper+Matches; public static final int Matches_Tobacco=Matches+Tobacco; public static final int Everything=Tobacco+Paper+Matches;

private int contains; public Table() {

} public synchronized void put(int what) { System.out.println(Thread.currentThread().getName() +":putting"+contains(what));

} public synchronized void get(int what) {

(what)+"-No!");

(what)+"-Yes!");

} public synchronized void DoneSmoking() {

} public String contains(int what) {

} } TableCS.java import java.util.*;

public class TableCS extends Table {

} cigarette.java import java.util.*; public class cigarette {

OUTPUT: D:\Java\jdk1.6.0\bin>javac Cigrate.java D:\Java\jdk1.6.0\bin>java Cigrate

Agent:Puttingtobaccopaper Smoker2:Gettingpapermatches-No! Smoker1:Gettingtobaccomatches-No! Smoker3:I Got What I Need!!! Smoker3:Rolling!! Smoker3:Smoking!! Smoker3:Done Smoking!! Smoker3:I Got What I Need!!! Smoker1:Gettingtobaccomatches-Yes! Smoker3:Rolling!! Smoker1:Gettingtobaccomatches-No! Smoker2:Gettingpapermatches-Yes! Smoker2:Gettingpapermatches-No!

Agent:Puttingtobaccomatches Smoker2:Gettingpapermatches-Yes! Smoker2:Gettingpapermatches-No! Smoker1:Gettingtobaccomatches-Yes! Smoker1:Gettingtobaccomatches-No! Smoker3:Smoking!!

Smoker3:Done Smoking!! Smoker3:Gettingtobaccopaper-No! Smoker1:GettingtobaccomatchesYes! Smoker1:GettingtobaccomatchesNo! Smoker2:GettingpapermatchesYes! Smoker2:GettingpapermatchesNo!

Agent:Puttingtobaccopaper Smoker2:GettingpapermatchesYes! Smoker2:GettingpapermatchesNo! Smoker1:GettingtobaccomatchesYes! Smoker1:GettingtobaccomatchesNo! Smoker3:GettingtobaccopaperYes! Smoker3:I Got What I Need!!! Smoker3:Rolling!! Smoker3:Smoking!! Smoker3:Done Smoking!! Smoker1:GettingtobaccomatchesYes! Smoker1:GettingtobaccomatchesNo! Smoker2:Gettingpapermatches-

Yes! Smoker2:GettingpapermatchesNo! Smoker3:Gettingtobaccopaper-No!

Agent:Puttingpapermatches

Smoker3:Gettingtobaccopaper-Yes! Smoker3:Gettingtobaccopaper-No! Smoker2:Gettingpapermatches-Yes! Smoker2:Gettingpapermatches-No! Smoker1:Gettingtobaccomatches-Yes! Smoker1:Gettingtobaccomatches-No!

RESULT: uses a monitor to synchronize the agent, thread and the three smoker threads are written and the output is executed successfully.

PROGRAM 3 Multiple sleeping barbers - Multiprocessor operating systems

sleeping barbers, all in one barbershop that has a finite number of chairs in the waiting room. Each customer is instantiated from a single Customer class, each barber is instantiated from a single Barber class. SLEEPING BARBERS PROBLEM AIM: sleeping barbers. ALGORI THM: Step1: The Barber (Thread/Process)

Step 2: P(access state) at this time he has been awakened, want to modify the number of available seats. Step 3: Number of free state++//one gets free. Step 4: V(Barber)//the barber is ready to cut.

Step 5: The customer (Thread/process)

Step 6: If the number of free seats is greater than 0, are any customers sitting down on a chair, notify the barber who is waiting that there is a customer. Step 7: V(access seats) dont need to lock the chairs anyone, now its this customers turn, but wait if wait the barber if busy, here the customer is having his hair cut. Step 8: Else there are no free seats Lock(V)(access seats) but release the

lock or the seats, customers leaves without a haircut. Step 9: Stop the program.

PROGRA M: SleepingBarber.java class Semaphore extends Object {

public class SleepingBarber extends Thread {

private class Customer extends Thread {

} public static void main(String args[]) {

} SleepingBarberD.java class Semaphore extends Object {

} public class SleepingBarberD extends Thread {

} private class Customer extends Thread {

} public void get_haircut() { haircut");

} OUTPUT: D:\Java\jdk1.6.0\bin> javac SleepingBarber.java D:\Java\jdk1.6.0\bin> java SleepingBarber

Barber0is cutting hair Customers0is getting his haircut Customers1is getting his haircut Barber1is cutting hair Barber2is cutting hair Customers2is getting his haircut Barber0is cutting hair Customers3is getting his haircut Barber1is cutting hair Customers4is getting his haircut Barber2is cutting hair Customers5is getting his haircut Barber0is cutting hair Customers6is getting his haircut Barber1is cutting hair Customers7is getting his haircut Barber2is cutting hair Customers8is getting his haircut Barber0is cutting hair Customers9is getting his haircut

Barber1is cutting hair Customers10is getting his haircut Barber2is cutting hair Customers16is getting his haircut

Barber0is cutting hair Customers17is getting his haircut Customers18is getting his haircut Barber1is cutting hair Barber2is cutting hair Customers23is getting his haircut Barber0is cutting hair Customers24is getting his haircut Barber1is cutting hair Customers25is getting his haircut Barber2is cutting hair Customers31is getting his haircut

RESULT: sleeping barbers using semaphores is written and the output is executed successfully

NETWORK OPERATING SYSTEMS PROGRAM 4 Network operating systems Establish a Lab setup for the following network operating systems based programs based on the skills in networking on your own. E.g. for identifying networking hardware, identifying different kinds of network cabling and network interface cards can be done. Exercises 1. Identifying Local Area Network Hardware 2. Exploring Local Area Network Configuration Options 3. Verifying TCP/IP Settings 4. Sharing Resources 5. Testing LAN Connections

Aim:

Algorithm: Step 1: Start the program. Step 2: Declare the IP address and MAC address to open a connection between corresponding systems. Step 3: Type ipconfig/all in command prompt, we get the IP address and MAC address of own system. Step 4: Type the MAC address as different formats. Step 5: Type the source code. Step 6: Compile the program and execute. Step 7: Run the program by declaring IP address and MAC address of destination. PROGRA M: WakeOnLan.java

import java.io.*; import java.net.*;

public class WakeOnLan {

IllegalArgumentException

OUTPUT: D:\Java\jdk1.6.0\bin>javac WakeOnLan.java D:\Java\jdk1.6.0\bin>java WakeOnLan 172.15.169.7 00-15-58-AC-0C-20 Wake on LAN packet sent

RESULT :
output is executed successfully.

PROGRAM 5 Real time operating systems clock, using C and Simple_OS] The program shall fulfill the following requirements: set the time, It shall be possible to set the alarm time, the alarm shall be
EN ABLED

when the alarm time is set, the alarm shall be AC TIVA TE when the alarm is D enabled, and when the current time is equal to the alarm time, an activated alarm must be acknowledged. Acknowledgement of an alarm shall lead to the alarm being DISABLED THE alarm is enabled again when a new alarm time is set, an alarm , which is not acknowledged shall be repeated every 10 seconds. The program shall communicate with a graphical user interface, where the current time shall be displayed, and where the alarm time shall be displayed when the alarm is enabled. It shall be possible to terminate the program, using a command which is sent from the graphical user interface.

AIM: To write a program using Real time operating system for implementing an alarm clock. ALGORI THM: Step 1: Start the program. Step 2: Display init is used for initialization and shall be called from the main function of the program before the processes are created. Step 3: Display alarm time a shows the current time and shall be called when a new alarm time is set. Step 4: Display time is used to display the current time and shall be called by the clock process.

Step 5: Erase the alarm time, erases the displayed alarm time and shall be called when the user acknowledges an alarm. Step 6: Display alarm text is used to show an alarm activation and the user is informed that the alarm has been activated. Step 7: when the alarm is activated the first time and when the alarm is activated repeatedly. Step 8: Erase alarm text,erase the information displayed by displays the alarm text. Step 9: Stop the program.

PROGRA M: Alarm.c #include<stdio.h> #include<conio.h> #include<dos.h> struct clk { }c1,c2; void clock(int *h1,int *m1,int *s1) {

} void timer(int *h,int *m,int *s)

} void alarm() {

} void main() {

\n\n\t\t\t\tPress any to Exit.");

} break; case 'T': case 't':

} OUTPUT: Press:-

Enter your Choice:A 24 hr Format(HH:MM:SS) Enter alarm time : 22:30:50 Alarm time: 22:20:50 Current Time: 22:19:53

Alarm time reached

Press:-

Enter your Choice: T

Enter time for timer (HH:MM:SS): 22:25:20

The Current Time:

Press:-

Enter your Choice:2

RESULT: alarm clock.is written and the output is executed successfully.

Anda mungkin juga menyukai