SlideShare une entreprise Scribd logo
1  sur  7
Télécharger pour lire hors ligne
Materi Penjadwalan dan Sikronisasi (FCFS-CubbyHole) - 21 Mei 2014|Hal 1 dari 3
Ujian 2
Matakuliah: Sistem Operasi
Jurusan: Informatika - Universitas Syiah Kuala
Semester Genap 2013/2014 - Pengajar: Arie Budiansyah, M.Eng.
--------------------------------------------------------------------------------------------------------------
Dibawah ini ada sebuah program penjadwalan FCFS dan sinkronisasi yang masih perlu
diperbaiki. Tugas anda adalah menyempurnakan program ini agar berjalan sesuai dengan konsep
penjadwalan dan sinkronisasi. *good luck.
“Bersemangatlah melakukan hal-hal yang bermanfaat bagimu dan jangan malas (putus asa)”
###############
import java.util.*;
class fcfs_sinkronisasi {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("enter no. of processes : ");
int n=sc.nextInt();
int[] process = new int[n+1];
int[] burst = new int[n+1];
int[] waiting = new int[n+1];
int[] turn =new int[n+1];
for(int m=1; m<=n; m++){
process[m]=m;
System.out.print("enter burst time of process "+m+": ");
burst[m]=sc.nextInt();
//System.out.println("");
}
turn[1]=burst[1]; // turnaround time of first process is equal to its burst time.
for(int i=2; i<=n; i++) {
turn[i]=burst[i]+turn[i-1];
waiting[i]=turn[i]-burst[i];
}
for (int i=1; i<=n; i++) {
System.out.print("Burst Time "+i+": "+burst[i]+" --> ");
System.out.println("Waiting Time "+i+": "+waiting[i]);
}
for (int i=1; i<=n; i++) {
CubbyHole ch = new CubbyHole();
//ch[0] = new CubbyHole();
Materi Penjadwalan dan Sikronisasi (FCFS-CubbyHole) - 21 Mei 2014|Hal 2 dari 3
Petugas pgs = new Petugas(ch, n, burst[i]);
//pgs[0] = new Petugas();
Kendaraan kdr = new Kendaraan(ch, n);
//kdr[0] = new Kendaraan();
//System.out.print("jumlah Process: "+process.length);
//System.out.println("burstTime: "+burst[i]);
//System.out.println("Process ke: "+i+" --> Burst Time: "+burst[i]);
//ch[i] = new CubbyHole();
//Petugas(ch, n, burst);
//kdr[i] = new Kendaraan(ch[i], n);
//System.out.print("ch: "+ch[i]);
//System.out.print("pgs: "+pgs[i]);
//System.out.println("kdr: "+kdr[i]);
pgs.start();
kdr.start();
}
}
}
class CubbyHole {
private int contents;
private boolean available = false;
public synchronized int get() {
while (available == false) {
try {
wait();
} catch (InterruptedException e) { }
}
available = false;
notifyAll();
return contents;
}
public synchronized void put(int value) {
while (available == true) {
try {
wait();
} catch (InterruptedException e) { }
}
contents = value;
available = true;
Materi Penjadwalan dan Sikronisasi (FCFS-CubbyHole) - 21 Mei 2014|Hal 3 dari 3
notifyAll();
}
}
class Petugas extends Thread {
private CubbyHole cubbyhole;
private int processLength;
private int burstTime;
public Petugas(CubbyHole c, int processLength, int burstTime) {
cubbyhole = c;
this.processLength = processLength;
this.burstTime = burstTime;
//System.out.println("jmlh Proses: "+ processLength);
}
public void run() {
for (int i = 1; i < this.processLength; i++) {
//System.out.print("BurstTime: "+ burstTime);
cubbyhole.put(i);
System.out.println("Petugas memberi tiket: " + i);
try {
sleep((int)(burstTime * 1000));
} catch (InterruptedException e) { }
}
}
}
class Kendaraan extends Thread {
private CubbyHole cubbyhole;
private int processLength;
public Kendaraan(CubbyHole c,int processLength) {
cubbyhole = c;
this.processLength = processLength;
}
public void run() {
int value = 0;
for (int i = 0; i < this.processLength; i++) {
value = cubbyhole.get();
System.out.println("Kendaraan mengambil tiket: " + value);
}
}
}
D:Bahan mengajarGenap20132014SOQUIS-SO_1208107010012_PerbaikanProgramFCFSfcfs_sinkronisasi.java 02 June 2014 16:10
/* NAMA : CUT DIRAYATI SAFIRA
* NIM : 1208107010012
* quis sistem operasi
*/
import java.util.*;
public class fcfs_sinkronisasi
{
public static void main(String args[]) {
System.out.println("====================================================");
System.out.println("ttFCFS & SINKRONISASItt");
System.out.println("By: CUT DIRAYATI SAFIRA - 1208107010012");
System.out.println("====================================================n");
Scanner sc = new Scanner(System.in);
System.out.print("Masukkan Banyak Kendaraan (n) : ");
int n=sc.nextInt();
System.out.print("n");
int[] process=new int[n+1];
int [] burst=new int[n+1];
int [] waiting=new int[n+1];
int[] turn=new int[n+1];
for(int m=0;m<n;m++){
process[m]=m;
System.out.print("Masukkan Burst Time dari Proses ke-"+(m+1)+" : ");
burst[m]=sc.nextInt();
System.out.print("n");
}
turn[0]=burst[0]; // turnaround time of first process is equal to its burst time.
for(int i=1;i<n;i++) {
turn[i]=burst[i]+turn[i-1];
waiting[i]=turn[i]-burst[i];
}
for(int i=0; i<n; i++){
System.out.print("Burst Time ke-"+(i+1)+" adalah "+burst[i]+" & ");
System.out.println("Waiting Time ke-"+(i+1)+" adalah "+waiting[i]);
}
System.out.print("n");
//ch[0]=new CubbyHole();
CubbyHole ch = new CubbyHole();
Petugas pgs = new Petugas(ch, n, burst);
//pgs[0] = new Petugas();
Kendaraan kdr = new Kendaraan(ch,n);
//kdr[0] = new Kendaraan();
//System.out.println("Jumlah Proses : "+process.length);
//System.out.println("burst time : "+burst[i]);
//System.out.println("Process ke : "+i+"--> Burst Time : "+burst[i]);
//ch[i] = new CubbyHole();
//Petugas(ch, n, burst);
//kdr[i]=new Kendaraan(ch[i],n);
-1-
D:Bahan mengajarGenap20132014SOQUIS-SO_1208107010012_PerbaikanProgramFCFSfcfs_sinkronisasi.java 02 June 2014 16:10
//System.out.println("ch: "+ch[i]);
//System.out.println("pgs: "+pgs[i]);
//System.out.println("kdr: "+kdr[i]);
pgs.start();
kdr.start();
}//}
/*int tot_turn=0,tot_wait=0;
for(int i=1;i<=n;i++){
tot_turn+=turn[i];
tot_wait+=waiting[i];
}
float avg_turn=(float)tot_turn/n;
float avg_wait=(float)tot_wait/n;
for(int m=1;m<=n;m++){
System.out.println("nprocess "+process[m]);
System.out.print("turn around time : "+turn[m]);
System.out.print(" waiting time : "+waiting[m]);
}
System.out.println("ntotal turn around time : "+tot_turn);
System.out.println("ntotal waiting time : "+tot_wait);
System.out.println("navg turn around time : "+avg_turn);
System.out.println("navg waiting time : "+avg_wait);*/
int i;
}
/* NAMA : CUT DIRAYATI SAFIRA
* NIM : 1208107010012
* quis sistem operasi
*/
public class Petugas extends Thread
{
private CubbyHole cubbyhole;
private int processLength;
private int[] burstTime;
public Petugas(CubbyHole c, int processLength, int[] burstTime ){
cubbyhole=c;
this.processLength = processLength;
this.burstTime = burstTime;
/*for(int i=0; i<processLength;i++){
System.out.println("burst "+i+": "+burstTime[i]);
}*/
//System.out.println("jumlah proses : "+processLength);
}
public void run(){
synchronized(cubbyhole){
for(int i=0; i<this.processLength; i++){
//System.out.print("Burst Time :+burstTime");
cubbyhole.put(i);
System.out.print("Petugas memberi tiket ke-"+(i+1)+" dengan Burst Time adalah "+
burstTime[i]);
-2-
D:Bahan mengajarGenap20132014SOQUIS-SO_1208107010012_PerbaikanProgramFCFSfcfs_sinkronisasi.java 02 June 2014 16:10
try{
sleep((int)((burstTime[i])*100));
}catch(InterruptedException e){
System.out.println(e);
}
}
}
}
}
class Kendaraan extends Thread{
private CubbyHole cubbyhole;
private int processLength;
public Kendaraan(CubbyHole c, int processLength){
cubbyhole=c;
this.processLength=processLength;
}
public void run(){
int value=0;
synchronized(cubbyhole){
for(int i=0; i<this.processLength; i++){
value=cubbyhole.get();
System.out.print(" dan Kendaraan mengambil tiket ke-"+(value+1)+"n");
}
}
}
}
/* NAMA : CUT DIRAYATI SAFIRA
* NIM : 1208107010012
* quis sistem operasi
*/
public class CubbyHole
{
private int contents;
private boolean available = false;
public synchronized int get() {
while (available == false) {
try {
wait();
} catch (InterruptedException e) { }
}
available = false;
notifyAll();
return contents;
}
public synchronized void put(int value) {
while (available == true) {
try {
wait();
-3-
D:Bahan mengajarGenap20132014SOQUIS-SO_1208107010012_PerbaikanProgramFCFSfcfs_sinkronisasi.java 02 June 2014 16:10
} catch (InterruptedException e) { }
}
contents = value;
available = true;
notifyAll();
}
}
-4-

Contenu connexe

Similaire à Ujian 2 MK SO FCFS Sinkronisasi java

Sheet1Address60741024Offsetaddress0102450506074120484026230723002p.docx
Sheet1Address60741024Offsetaddress0102450506074120484026230723002p.docxSheet1Address60741024Offsetaddress0102450506074120484026230723002p.docx
Sheet1Address60741024Offsetaddress0102450506074120484026230723002p.docxbagotjesusa
 
C++ C++ C++ In Chapter 1- the class clockType was designed to implem.docx
C++ C++ C++   In Chapter 1- the class clockType was designed to implem.docxC++ C++ C++   In Chapter 1- the class clockType was designed to implem.docx
C++ C++ C++ In Chapter 1- the class clockType was designed to implem.docxCharlesCSZWhitei
 
Document 14 (6).pdf
Document 14 (6).pdfDocument 14 (6).pdf
Document 14 (6).pdfRajMantry
 
Lecture_Slide_4.pptx
Lecture_Slide_4.pptxLecture_Slide_4.pptx
Lecture_Slide_4.pptxDiptoRoy21
 
Object Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical FileObject Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical FileHarjinder Singh
 
C++ project
C++ projectC++ project
C++ projectSonu S S
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxstilliegeorgiana
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxdenneymargareta
 
Online_Examination
Online_ExaminationOnline_Examination
Online_ExaminationRupam Dey
 
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docxkatherncarlyle
 
How To Build Efficient ML Pipelines From The Startup Perspective (OpenInfraDa...
How To Build Efficient ML Pipelines From The Startup Perspective (OpenInfraDa...How To Build Efficient ML Pipelines From The Startup Perspective (OpenInfraDa...
How To Build Efficient ML Pipelines From The Startup Perspective (OpenInfraDa...Jaeman An
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfjaipur2
 
【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニック
【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニック【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニック
【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニックUnity Technologies Japan K.K.
 
Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfPlease I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfankit11134
 
Assignment 02 Process State SimulationCSci 430 Introduction to.docx
Assignment 02 Process State SimulationCSci 430 Introduction to.docxAssignment 02 Process State SimulationCSci 430 Introduction to.docx
Assignment 02 Process State SimulationCSci 430 Introduction to.docxcargillfilberto
 

Similaire à Ujian 2 MK SO FCFS Sinkronisasi java (20)

OOPs manual final copy
OOPs manual final   copyOOPs manual final   copy
OOPs manual final copy
 
Sheet1Address60741024Offsetaddress0102450506074120484026230723002p.docx
Sheet1Address60741024Offsetaddress0102450506074120484026230723002p.docxSheet1Address60741024Offsetaddress0102450506074120484026230723002p.docx
Sheet1Address60741024Offsetaddress0102450506074120484026230723002p.docx
 
C++ C++ C++ In Chapter 1- the class clockType was designed to implem.docx
C++ C++ C++   In Chapter 1- the class clockType was designed to implem.docxC++ C++ C++   In Chapter 1- the class clockType was designed to implem.docx
C++ C++ C++ In Chapter 1- the class clockType was designed to implem.docx
 
Document 14 (6).pdf
Document 14 (6).pdfDocument 14 (6).pdf
Document 14 (6).pdf
 
Lecture_Slide_4.pptx
Lecture_Slide_4.pptxLecture_Slide_4.pptx
Lecture_Slide_4.pptx
 
Object Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical FileObject Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical File
 
C++ project
C++ projectC++ project
C++ project
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docx
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docx
 
Online_Examination
Online_ExaminationOnline_Examination
Online_Examination
 
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
 
How To Build Efficient ML Pipelines From The Startup Perspective (OpenInfraDa...
How To Build Efficient ML Pipelines From The Startup Perspective (OpenInfraDa...How To Build Efficient ML Pipelines From The Startup Perspective (OpenInfraDa...
How To Build Efficient ML Pipelines From The Startup Perspective (OpenInfraDa...
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdf
 
【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニック
【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニック【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニック
【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニック
 
Caps a tool for process scheduling
Caps a tool for process schedulingCaps a tool for process scheduling
Caps a tool for process scheduling
 
Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfPlease I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdf
 
COCOMO MODEL
COCOMO MODELCOCOMO MODEL
COCOMO MODEL
 
Concurrency in Python4k
Concurrency in Python4kConcurrency in Python4k
Concurrency in Python4k
 
Assignment 02 Process State SimulationCSci 430 Introduction to.docx
Assignment 02 Process State SimulationCSci 430 Introduction to.docxAssignment 02 Process State SimulationCSci 430 Introduction to.docx
Assignment 02 Process State SimulationCSci 430 Introduction to.docx
 
Lecture 8 9 process_concept
Lecture 8 9 process_conceptLecture 8 9 process_concept
Lecture 8 9 process_concept
 

Dernier

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 

Dernier (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

Ujian 2 MK SO FCFS Sinkronisasi java

  • 1. Materi Penjadwalan dan Sikronisasi (FCFS-CubbyHole) - 21 Mei 2014|Hal 1 dari 3 Ujian 2 Matakuliah: Sistem Operasi Jurusan: Informatika - Universitas Syiah Kuala Semester Genap 2013/2014 - Pengajar: Arie Budiansyah, M.Eng. -------------------------------------------------------------------------------------------------------------- Dibawah ini ada sebuah program penjadwalan FCFS dan sinkronisasi yang masih perlu diperbaiki. Tugas anda adalah menyempurnakan program ini agar berjalan sesuai dengan konsep penjadwalan dan sinkronisasi. *good luck. “Bersemangatlah melakukan hal-hal yang bermanfaat bagimu dan jangan malas (putus asa)” ############### import java.util.*; class fcfs_sinkronisasi { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.print("enter no. of processes : "); int n=sc.nextInt(); int[] process = new int[n+1]; int[] burst = new int[n+1]; int[] waiting = new int[n+1]; int[] turn =new int[n+1]; for(int m=1; m<=n; m++){ process[m]=m; System.out.print("enter burst time of process "+m+": "); burst[m]=sc.nextInt(); //System.out.println(""); } turn[1]=burst[1]; // turnaround time of first process is equal to its burst time. for(int i=2; i<=n; i++) { turn[i]=burst[i]+turn[i-1]; waiting[i]=turn[i]-burst[i]; } for (int i=1; i<=n; i++) { System.out.print("Burst Time "+i+": "+burst[i]+" --> "); System.out.println("Waiting Time "+i+": "+waiting[i]); } for (int i=1; i<=n; i++) { CubbyHole ch = new CubbyHole(); //ch[0] = new CubbyHole();
  • 2. Materi Penjadwalan dan Sikronisasi (FCFS-CubbyHole) - 21 Mei 2014|Hal 2 dari 3 Petugas pgs = new Petugas(ch, n, burst[i]); //pgs[0] = new Petugas(); Kendaraan kdr = new Kendaraan(ch, n); //kdr[0] = new Kendaraan(); //System.out.print("jumlah Process: "+process.length); //System.out.println("burstTime: "+burst[i]); //System.out.println("Process ke: "+i+" --> Burst Time: "+burst[i]); //ch[i] = new CubbyHole(); //Petugas(ch, n, burst); //kdr[i] = new Kendaraan(ch[i], n); //System.out.print("ch: "+ch[i]); //System.out.print("pgs: "+pgs[i]); //System.out.println("kdr: "+kdr[i]); pgs.start(); kdr.start(); } } } class CubbyHole { private int contents; private boolean available = false; public synchronized int get() { while (available == false) { try { wait(); } catch (InterruptedException e) { } } available = false; notifyAll(); return contents; } public synchronized void put(int value) { while (available == true) { try { wait(); } catch (InterruptedException e) { } } contents = value; available = true;
  • 3. Materi Penjadwalan dan Sikronisasi (FCFS-CubbyHole) - 21 Mei 2014|Hal 3 dari 3 notifyAll(); } } class Petugas extends Thread { private CubbyHole cubbyhole; private int processLength; private int burstTime; public Petugas(CubbyHole c, int processLength, int burstTime) { cubbyhole = c; this.processLength = processLength; this.burstTime = burstTime; //System.out.println("jmlh Proses: "+ processLength); } public void run() { for (int i = 1; i < this.processLength; i++) { //System.out.print("BurstTime: "+ burstTime); cubbyhole.put(i); System.out.println("Petugas memberi tiket: " + i); try { sleep((int)(burstTime * 1000)); } catch (InterruptedException e) { } } } } class Kendaraan extends Thread { private CubbyHole cubbyhole; private int processLength; public Kendaraan(CubbyHole c,int processLength) { cubbyhole = c; this.processLength = processLength; } public void run() { int value = 0; for (int i = 0; i < this.processLength; i++) { value = cubbyhole.get(); System.out.println("Kendaraan mengambil tiket: " + value); } } }
  • 4. D:Bahan mengajarGenap20132014SOQUIS-SO_1208107010012_PerbaikanProgramFCFSfcfs_sinkronisasi.java 02 June 2014 16:10 /* NAMA : CUT DIRAYATI SAFIRA * NIM : 1208107010012 * quis sistem operasi */ import java.util.*; public class fcfs_sinkronisasi { public static void main(String args[]) { System.out.println("===================================================="); System.out.println("ttFCFS & SINKRONISASItt"); System.out.println("By: CUT DIRAYATI SAFIRA - 1208107010012"); System.out.println("====================================================n"); Scanner sc = new Scanner(System.in); System.out.print("Masukkan Banyak Kendaraan (n) : "); int n=sc.nextInt(); System.out.print("n"); int[] process=new int[n+1]; int [] burst=new int[n+1]; int [] waiting=new int[n+1]; int[] turn=new int[n+1]; for(int m=0;m<n;m++){ process[m]=m; System.out.print("Masukkan Burst Time dari Proses ke-"+(m+1)+" : "); burst[m]=sc.nextInt(); System.out.print("n"); } turn[0]=burst[0]; // turnaround time of first process is equal to its burst time. for(int i=1;i<n;i++) { turn[i]=burst[i]+turn[i-1]; waiting[i]=turn[i]-burst[i]; } for(int i=0; i<n; i++){ System.out.print("Burst Time ke-"+(i+1)+" adalah "+burst[i]+" & "); System.out.println("Waiting Time ke-"+(i+1)+" adalah "+waiting[i]); } System.out.print("n"); //ch[0]=new CubbyHole(); CubbyHole ch = new CubbyHole(); Petugas pgs = new Petugas(ch, n, burst); //pgs[0] = new Petugas(); Kendaraan kdr = new Kendaraan(ch,n); //kdr[0] = new Kendaraan(); //System.out.println("Jumlah Proses : "+process.length); //System.out.println("burst time : "+burst[i]); //System.out.println("Process ke : "+i+"--> Burst Time : "+burst[i]); //ch[i] = new CubbyHole(); //Petugas(ch, n, burst); //kdr[i]=new Kendaraan(ch[i],n); -1-
  • 5. D:Bahan mengajarGenap20132014SOQUIS-SO_1208107010012_PerbaikanProgramFCFSfcfs_sinkronisasi.java 02 June 2014 16:10 //System.out.println("ch: "+ch[i]); //System.out.println("pgs: "+pgs[i]); //System.out.println("kdr: "+kdr[i]); pgs.start(); kdr.start(); }//} /*int tot_turn=0,tot_wait=0; for(int i=1;i<=n;i++){ tot_turn+=turn[i]; tot_wait+=waiting[i]; } float avg_turn=(float)tot_turn/n; float avg_wait=(float)tot_wait/n; for(int m=1;m<=n;m++){ System.out.println("nprocess "+process[m]); System.out.print("turn around time : "+turn[m]); System.out.print(" waiting time : "+waiting[m]); } System.out.println("ntotal turn around time : "+tot_turn); System.out.println("ntotal waiting time : "+tot_wait); System.out.println("navg turn around time : "+avg_turn); System.out.println("navg waiting time : "+avg_wait);*/ int i; } /* NAMA : CUT DIRAYATI SAFIRA * NIM : 1208107010012 * quis sistem operasi */ public class Petugas extends Thread { private CubbyHole cubbyhole; private int processLength; private int[] burstTime; public Petugas(CubbyHole c, int processLength, int[] burstTime ){ cubbyhole=c; this.processLength = processLength; this.burstTime = burstTime; /*for(int i=0; i<processLength;i++){ System.out.println("burst "+i+": "+burstTime[i]); }*/ //System.out.println("jumlah proses : "+processLength); } public void run(){ synchronized(cubbyhole){ for(int i=0; i<this.processLength; i++){ //System.out.print("Burst Time :+burstTime"); cubbyhole.put(i); System.out.print("Petugas memberi tiket ke-"+(i+1)+" dengan Burst Time adalah "+ burstTime[i]); -2-
  • 6. D:Bahan mengajarGenap20132014SOQUIS-SO_1208107010012_PerbaikanProgramFCFSfcfs_sinkronisasi.java 02 June 2014 16:10 try{ sleep((int)((burstTime[i])*100)); }catch(InterruptedException e){ System.out.println(e); } } } } } class Kendaraan extends Thread{ private CubbyHole cubbyhole; private int processLength; public Kendaraan(CubbyHole c, int processLength){ cubbyhole=c; this.processLength=processLength; } public void run(){ int value=0; synchronized(cubbyhole){ for(int i=0; i<this.processLength; i++){ value=cubbyhole.get(); System.out.print(" dan Kendaraan mengambil tiket ke-"+(value+1)+"n"); } } } } /* NAMA : CUT DIRAYATI SAFIRA * NIM : 1208107010012 * quis sistem operasi */ public class CubbyHole { private int contents; private boolean available = false; public synchronized int get() { while (available == false) { try { wait(); } catch (InterruptedException e) { } } available = false; notifyAll(); return contents; } public synchronized void put(int value) { while (available == true) { try { wait(); -3-
  • 7. D:Bahan mengajarGenap20132014SOQUIS-SO_1208107010012_PerbaikanProgramFCFSfcfs_sinkronisasi.java 02 June 2014 16:10 } catch (InterruptedException e) { } } contents = value; available = true; notifyAll(); } } -4-