Sistem Operasi 3
“Process”
Konsep Proses
• Proses adalah suatu program yang sedang
dieksekusi
– Harus dijalankan secara sekuensial
• Suatu proses meliputi:
– Program counter
• Tempat untuk menyimpan alamat suatu proses yang akan dieksekusi selanjutnya
– Stack
• Tempat penyimpanan temporary data yang dibutuhkan selama program dieksekusi
– Data section
Status Proses
•
New
: pada saat proses pertama kali
dibuat
•
Running
: pada saat proses sedang
dieksekusi
•
Waiting
: proses menunggu suatu event
lain (contoh: proses I/O)
•
Ready
: proses siap untuk diekseskusi
•
Terminated
: pada saat proses sudah
Program Control Block
• Setiap proses direpresentasikan kedalam sistem
operasi oleh PCB
• PCB meliputi informasi yang berhubungan
dengan proses:
– Process state – Program counter – CPU registers
– CPU scheduling information
– Memory-management information – Accounting information
Penjadwalan Antrian Proses
•
job queue
: ketika proses memasuki
sistem
•
ready queue
: proses yang hidup pada
memori utama, siap dan menunggu untuk
di-eksekusi
•
device queue
: bila proses tersebut
menunggu peralatan I/O tertentu
Penjadwal Antrian
•
Long-term scheduler (or job scheduler)
:
menentukan proses mana yang harus
dimasukkan ke dalam ready queue.
•
Short-term scheduler (or CPU
Scheduler
• Short-term scheduler lebih sering dipanggil
(hanya dalam waktu millisecond).
• Long-term scheduler jarang dipanggil (dalam
hitungan detik, menit).
• Proses dapat juga dibagi atas 2 macam :
– I/O-bound process – menghabiskan waktu lebih
banyak untuk mengerjakan I/O daripada di CPU short CPU bursts.
Context Switch
• Pada saat CPU beralih ke proses lain,
sistem harus menyimpan state dari proses
lama dan mengambil state dari proses
yang baru.
• Tugas ini dilakukan oleh context switch
• Context-switch time is
overhead
; the
system
does no useful work
while
switching
Process Creation
• Parent process create children processes
– Pada saat menciptakan proses baru, dibentuk dalam bentuk Tree
• Generally, process identified and managed via a process identifier (pid)
• Resource sharing
– Parent and children share all resources
– Children share subset of parent’s resources – Parent and child share no resources
• Execution
– Parent and children execute concurrently – Parent waits until children terminate
• UNIX examples
– fork system call creates new process
Process Termination
• Process mengesekusi perintah terakhir dan
meminta OS untuk mengapusnya (exit)
– Menampilkan data dari child ke parent (via wait) – Sumber daya proses tersebut didealokasi oleh OS
• Parent akan men-terminate eksekusi child
dengan paksa (abort), karena
– Child telah menghabiskan resources
– Task yang ditugaskan pada child sudah selesai – Jika parent melakukan exiting
• Beberapa OS tidak memperbolehkan child untuk melanjutkan kegiatannya
Interprocess Comunication
• Sistem operasi kebanyakan menjalankan
program secara simultan (concurrent).
• Program yang dijalankan secara simultan
itu dapat bekerja sama (coorperating)
Alasan Coorperating Process
• Information Sharing: menggunakan informasi(resource) yang sama untuk beberapa proses
• Computation Speedup : suatu task tertentu bisa dipecah menjadi beberapa cooperating processes sehingga bisa dikerjakan secara paralel sehingga menjadi lebih cepat selesai
• Modularity : pembuatan suatu sistem yang moduler
dengan memecahkan fungsi-fungsi dari sistem tersebut menjadi beberapa proses atau thread
• Convenience : user bisa dengan mudah mengerjakan sesuatu yang berbeda dalam waktu yang sama
Communications Models
Produsen dan Konsumer
• Produsen : memproduksi barang • Konsumer : menghabiskan barang
• Perlu diperhatikan bahwa barang yang diproduksi oleh produsen dan yang dihabiskan oleh konsumer adalah sama
• Suatu paradigma yang umum untuk cooperating processes
• Terdapat 2 macam consumer-producer problem:
– Unbounded-buffer: Tidak adanya batas bagi produsen untuk memproduksi barang
– Bounded-buffer: adanya suatu batas bagi produsen untuk memproduksi barang
Bounded-Buffer – Shared-Memory Solution
• Shared data
#define BUFFER_SIZE 10 typedef struct {
. . . } item;
item buffer[BUFFER_SIZE]; int in = 0;
int out = 0;
Bounded-Buffer – Producer
while (true) {
/* Produce an item */
while (((in = (in + 1) % BUFFER SIZE count) == out); /* do nothing -- no free buffers */
buffer[in] = item;
Bounded Buffer – Consumer
while (true) {
while (in == out)
; // do nothing -- nothing to consume
// remove an item from the buffer item = buffer[out];
out = (out + 1) % BUFFER SIZE; return item;
Interprocess Communication – Message Passing
• Mekanisme proses untuk berkomunikasi dan
sinkroniasi aksi
• IPC melakukan dua operasi:
– send(message) – message size fixed or variable – receive(message)
• Jika
P
dan
Q
ingin berkomunikasi, mereka
harus:
– establish a communication link between them – exchange messages via send/receive
• Implementation of communication link
Direct Communication
• Processes harus memanggil masing-masing:
– send (P, message) – send a message to process P – receive(Q, message) – receive a message from
process Q
• Properties of communication link
– Links dibentuk secara otomatis
– Sebuah link diasosiasikan dengan suatu hubungan sepasang proses
– Antara setiap pasang pasti memiliki tepat satu link – The link bisa unidirectional, tapi biasanya
Indirect Communication
• Messages diarahkan dan diterima dari mailboxes (atau biasa disebut ports)
– Each mailbox has a unique id
– Processes dapat berkomunikasi jika mereka saling sharing mailbox
• Properties of communication link
– Link dibangun jika masing-masing proses saling share mailbox yang umum
– Sebuah link dapat diasosiasikan dengan banyak processes – Setiap pasang proses dapat share beberapa communication
links
Indirect Communication
• Operations
– create a new mailbox
– send and receive messages through mailbox – destroy a mailbox
• Primitives are defined as:
send(
A, message
) – send a message to
mailbox A
Indirect Communication
• Mailbox sharing
– P1, P2, and P3 share mailbox A – P1, sends; P2 and P3 receive – Who gets the message?
• Solutions
– Memperbolehkan sebuah link untuk diasosikan maksimal 2 proses
– Memperbolehkan hanya 1 process dalam satu waktu untuk menerima message
– Memperbolehkan system untuk memilih siapa
Synchronization
• Message passing may be either blocking or non-blocking
• Blocking is considered synchronous
– Blocking send : sender memblok sampai message diterima – Blocking receive : receiver memblok sampai message
tersedia
• Non-blocking is considered asynchronous
– Non-blocking : setelah mengirim, sender melanjutkan kegiatannya, tidak perlu menunggu message diterima
Buffering
• Antrian message yang ditempatkan
pada link; diimplementasikan dengan:
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
Communications in Client-Server Systems
• Sockets
• Remote Procedure Calls
Sockets
• Sebuah programming interface ke OS yang memungkinkan proses untuk saling berkomunikasi ke proses lainya
• The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8
Client
Remote Procedure Calls
• Remote procedure call (RPC) mengabstraksikan
procedure calls antara processes pada jaringan
•
Stubs
– client-side proxy for the actual
procedure on the server
•
Skeleton
– server side proxy
• The client-side stub locates the server and
marshalls
the parameters
• The server-side stub receives this message,
unpacks the marshalled parameters, and
Remote Method Invocation
• Remote Method Invocation (RMI) is a Java mechanism similar to RPCs
RMI Layers
TCP
Remote Reference Layer
Transport Layer Java Virtual Machine
Client Object
Remote Reference Layer
Transport Layer Java Virtual Machine
Stub
Remote Object
Copyright © 1997 Alex Chaffee
RMI System Architecture
Client Virtual Machine
Client
Server Virtual Machine
Stub
Remote Object
Skeleton
Registry Virtual Machine “Fred”
Copyright © 1997 Alex Chaffee
RMI Flow
Client Virtual Machine
Client
Server Virtual Machine
Stub
Remote Object
Skeleton
Registry Virtual Machine “Fred”
Server
1
2
Copyright © 1997 Alex Chaffee
RMI Flow
Client Virtual Machine
Client
Server Virtual Machine
Stub
Remote Object
Skeleton
Registry Virtual Machine
“Fred”
Server
4
3. Client requests object from Registry 4. Registry returns remote reference (and stub gets created)
Copyright © 1997 Alex Chaffee
RMI Flow
Client Virtual Machine
Client
Server Virtual Machine
Stub
Remote Object
Skeleton
Registry Virtual Machine
“Fred”
Server
6
5. Client invokes stub method 6. Stub talks to skeleton
7. Skeleton invokes remote object method