Antonius Rachmat C, S.Kom, M.Cs
Sistem Operasi 3
“Process”
Antonius Rachmat C, S.Kom, M.Cs
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
- Mengandung variabel global dari suatu proses
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 selesai dieksekusi
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
- – I/O status 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
- Setiap proses akan berpindah dari satu antrian ke antrian lain
Penjadwal Antrian
• Long-term scheduler (or job scheduler):
menentukan proses mana yang harus dimasukkan ke dalam ready queue.- Short-term scheduler (or CPU
scheduler): menentukan proses mana yang selanjutnya akan dieksekusi dan mengalokasikan 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.
- – CPU-bound process – jarang melakukan permintaan
I/O, menggunakan lebih banyak waktunya di CPU long 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
- Time dependent on hardware support
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
– exec system call used after a fork to replace the 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– All children terminated - cascading termination
Interprocess Comunication
• Sistem operasi kebanyakan menjalankan
program secara simultan (concurrent).• Program yang dijalankan secara simultan
itu dapat bekerja sama (coorperating) dengan proses lain ataupun bekerja sendiri (independent)
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
- – Contoh : satu user bisa saja secara bersamaan mengetik dan mengedit serta mencetak suatu halaman tertentu
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- Consumer harus menunggu sampai buffer kosong dan producer harus menunggu sampai buffer penuh
- Shared data
#define BUFFER_SIZE 10 typedef struct { . . . } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0;
- Solution is correct, but can only use
Bounded-Buffer – Producer
while (true) { /* Produce an item */ while (((in = (in + 1) % BUFFER SIZE count)
== out); /* do nothing -- no free buffers */ buffer[in] = item; in = (in + 1) % BUFFER SIZE;
}
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
- – physical (e.g., shared memory, hardware bus)
- – logical (e.g., logical properties)
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 bi- directional
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
- – Sebuah link dapat diasosiasikan dengan banyak processes
- – Setiap pasang proses dapat share beberapa communication links
- – Link bisa unidirectional atau bi-directional
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 receive(A, message) – receive a message from mailbox A
Indirect Communication
- Mailbox sharing
- – P , P , and P share mailbox A
1
2
3
- – P , sends; P and P receive
1
2
3
- – Who gets the message?
- Solutions
- – Memperbolehkan hanya 1 process dalam satu waktu untuk menerima message
- – Memperbolehkan system untuk memilih siapa penerimanya. Sender diberitahu siapa yang receiver yang menerimanya.
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
- – Non-blocking receiver menerima message baik valid ataupun tidak (null)
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
3. Unbounded capacity – infinite length
Sender never waits
Communications in Client-Server Systems
- Sockets • Remote Procedure Calls • Remote Method Invocation (Java)
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 • Communication consists between a pair of sockets •
Server
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 peforms the procedure on the server
Remote Method Invocation
Remote Method Invocation (RMI) is a Java mechanism similar to • RPCs RMI allows a Java program on one machine to invoke a method on • a remote object
RMI Layers
TCP
Remote Reference Layer Transport Layer Java Virtual Machine
Client Object
Remote Reference Layer Transport Layer Java Virtual Machine
Stub Remote
Object Skeleton RMI System Architecture Client Virtual Machine
Client Server Virtual Machine
Stub Remote Object
Skeleton “Fred”
Server RMI Flow
1. Server Creates Remote Object Client Virtual Machine Server Virtual Machine
2. Server Registers Remote Object Client
Remote Object 1 Skeleton Stub Server
2 “Fred” RMI Flow Client Virtual Machine Server Virtual Machine
Client Remote
Object
4. Registry returns remote reference (and stub gets created) Skeleton Stub 3 4 Server
“ Fred ”
RMI Flow
Client Virtual Machine Server Virtual Machine
Client Remote 5 7 Object
Stub Server
5. Client invokes stub method
6. Stub talks to skeleton
7. Skeleton invokes remote object “Fred” method NEXT