You are on page 1of 79

Bölüm 3: İşlemler (Processes)

Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Outline
▪ İşlem Kavramı
▪ İşlem Planlama (Scheduling)
▪ İşlemlerle İlgili İşlemler
▪ İşlemler arası iletişim (IPC)
▪ Paylaşımlı Bellek Sistemlerinde IPC
▪ Mesaj Geçiş Sistemlerinde IPC
▪ IPC Sistemlerine Örnekler
▪ İstemci-Sunucu Sistemlerinde İletişim

Operating System Concepts – 10th Edition 3.2 Silberschatz, Galvin and Gagne ©2018
Objectives
▪ Identify the separate components of a process and illustrate how they
are represented and scheduled in an operating system.
▪ Describe how processes are created and terminated in an operating
system, including developing programs using the appropriate system
calls that perform these operations.
▪ Describe and contrast interprocess communication using shared
memory and message passing.
▪ Design programs that uses pipes and POSIX shared memory to
perform interprocess communication.
▪ Describe client-server communication using sockets and remote
procedure calls.
▪ Design kernel modules that interact with the Linux operating system.

Operating System Concepts – 10th Edition 3.3 Silberschatz, Galvin and Gagne ©2018
İşlem (Process) Kavramı
▪ Bir işletim sistemi, bir process olarak çalışan çeşitli programları
yürütür.
▪ İşlem (Process):- yürütülmekte olan bir program; işlemin yürütülmesi
sıralı bir şekilde ilerlemelidir.
▪ İşlem aşağıdakileri içermektedir:
• Program Kodu (Text Section)
• Program Counter (İşlemcide bir sonraki işletilecek komutun ana
bellekteki adresini tutan 'register' dır.)
• Stack (yığın), (alt program değişkenleri, dönüş adresleri vb.
değerleri içerir)
• Veri (Değişkenleri, Diziler, Listeler)
• Heap (Nesneler)

Operating System Concepts – 10th Edition 3.4 Silberschatz, Galvin and Gagne ©2018
İşlem (Process) Kavramı

▪ Program, diskte depolanan pasif varlıktır (yürütülebilir


dosya/executable file); işlem ise aktiftir.

• Çalıştırılabilir bir dosya belleğe yüklendiğinde program işleme


dönüşür.

▪ Programın çalıştırılması GUI fare tıklamaları, program adının komut


satırıyla girişi vb. ile başlatılır.

▪ Bir program birden fazla işlem olarak yürütülebilir.

• Aynı programı çalıştıran birden fazla kullanıcıyı düşünebiliriz.

Operating System Concepts – 10th Edition 3.5 Silberschatz, Galvin and Gagne ©2018
İşlem (Process) Kavramı

▪ Örneğin, Windows işletim sisteminde Word programı, web tarayıcı,


e-posta kontrolüne ait programlar aynı anda çalışabilmektedir.

▪ İş (job) veye işlem (process) aynı anlamda kullanılmaktadır.

▪ Exe bir dosya ya tıklayarak çalıştırma işlemi başlatmaktadır.

▪ İşlemler program counter, register, stack, heap (işleme atanan


dinamik bellek) alanlarını kullanırlar.

Operating System Concepts – 10th Edition 3.6 Silberschatz, Galvin and Gagne ©2018
Bellekteki İşlem (Process in Memory)

Operating System Concepts – 10th Edition 3.7 Silberschatz, Galvin and Gagne ©2018
C Programının Bellek Yerleşimi

Operating System Concepts – 10th Edition 3.8 Silberschatz, Galvin and Gagne ©2018
İşlem (Process) Durumu

▪ Bir işlemin hangi durumda olduğunu gösteren ve işlemin ömrü


boyunca değişken bir durumu bulunmaktadır. Bunlar;

• Yeni (New): İşlemin oluşturulduğunu gösterir.

• Çalışıyor (Running): İşlemin komutları yürütülmektedir.

• Bekliyor (Waiting): İşlem bir olayın gerçekleşmesini beklemektedir.


Örneğin bir GÇ işlemi.

• Hazır (Ready): İşlem bir işlemciye atanmak için beklemektedir.

• Bitti (Terminated): İşlem çalışmasını bitirdi.

Operating System Concepts – 10th Edition 3.9 Silberschatz, Galvin and Gagne ©2018
İşlem (Process) Durum Diyagramı

Operating System Concepts – 10th Edition 3.10 Silberschatz, Galvin and Gagne ©2018
İşlem Kontrol Bloğu
(Process Control Block , PCB)

İşletim sisteminde her işlem, işlem kontrol bloğu ile temsil edilmektedir.

▪ İşlem Durumu: İşlem yeni başlamış, hazır, yürütülüyor,


beklemekte vb. durumlarda olabilmektedir.

▪ İşlem Numarası: Her işlemin bir ID’ si bulunmaktadır.

▪ Program Sayacı: Sayaç, işlem için yürütülmesi gereken


bir sonraki komutun adresini gösterir.

▪ CPU Registers (Mikroişlemci Kayıt Edicileri): Kayıt


ediciler bilgisayar mimarisine göre sayı ve çeşit olarak
değişebilmektedir.

▪ Mikroişlemci Programlama Bilgileri: Bu bilgiler, işlem


önceliğini, programın sıra göstergecini ve diğer
programlama değişkenlerini içermektedir.

Operating System Concepts – 10th Edition 3.11 Silberschatz, Galvin and Gagne ©2018
İşlem Kontrol Bloğu
(Process Control Block , PCB)

İşletim sisteminde her işlem, işlem kontrol bloğu ile temsil edilmektedir.

▪ Bellek Yönetim Bilgileri: Bu bilgiler taban ve limit


kayıtçılarının değerlerini, sayfa tablolarını veya işletim
sistemi tarafından kullanılan bellek sistemine göre
değişen segment tablosunu içerir.

▪ Hesaplama Bilgileri: Bu bilgiler, mikroişlemcini


kullandığı gerçek zaman sınırlamaları, hesap
numaraları, iş ve işlem numaraları gibi bilgileri içerir.
Giriş/çıkış durum bilgileri; işlem için ayrılmış giriş/çıkış
aygıtlarının ve açık dosyaların listesi gibi bilgileri
kapsar.

Operating System Concepts – 10th Edition 3.12 Silberschatz, Galvin and Gagne ©2018
İşlemden İşleme CPU Geçişi (Switch)
Context switch, CPU bir işlemden diğerine geçtiğinde
gerçekleşir.

Operating System Concepts – 10th Edition 3.13 Silberschatz, Galvin and Gagne ©2018
İşlemden İşleme CPU Geçişi (Switch)

▪ CPU başka bir işleme geçtiğinde, sistem eski işlemin durumunu


kaydetmeli ve yeni işlem için kaydedilmiş durumu bir bağlam anahtarı
(context switch) aracılığıyla yüklemelidir.

▪ Context of a process represented in the PCB

▪ Bağlam değiştirme süresi tamamen ek yüktür; sistem kullanımı geçiş


yaparken idle (boş) durumdadır.

▪ İşletim sistemi ve PCB ne kadar karmaşıksa, bağlam anahtarı da o


kadar uzun olur

▪ Donanım desteğine bağlı zaman

• Bazı donanımlar, CPU başına birden çok yazmaç seti (register set)
sağlar➔ aynı anda birden çok bağlam yüklenir.

Operating System Concepts – 10th Edition 3.14 Silberschatz, Galvin and Gagne ©2018
İşlem / İş Parçacığı (Thread)
▪ İşlemin eş zamanlı olarak işlenen her bir bölümüdür.

▪ İş parçacığı ve işlem arasındaki fark bir işletim sisteminden iş


parçacığının oluşturuluşu ve kaynakların paylaşılmasıdır.

▪ Çoğu durumda iş parçacıkları işlemlerin içinde yer alır, onları


oluştururlar.

▪ Çoklu iş parçacıkları paralel olarak pek çok bilgisayar sisteminde


uygulanabilir.

▪ İşlemler aynı kaynakları paylaşmazlar (bellek gibi). Fakat aynı işlem


içindeki farklı thread’ ler aynı kaynakları paylaşabilirler.

▪ Bölüm 4’ de ayrıntılı olarak işlenecek.

Operating System Concepts – 10th Edition 3.15 Silberschatz, Galvin and Gagne ©2018
İşlem Programlama (Scheduling)

▪ Multiprogramming’ in amacı CPU kullanımını maksimize etmek için,


her zaman çalışan işlemler olmasını sağlamaktır.

▪ Process scheduler, CPU çekirdeğinde bir sonraki yürütme için


mevcut işlemler arasından seçim yapar.

▪ Hedef - CPU kullanımını en üst düzeye çıkarıp, işlemleri hızla CPU


çekirdeğine geçirimek.

▪ Süreçlerin zamanlama sıralarını (scheduling queues) korur.

Operating System Concepts – 10th Edition 3.16 Silberschatz, Galvin and Gagne ©2018
İşlem Planlama Sıraları
(Process Scheduling Queues)

▪ İş (job) kuyruğu - Sistemdeki tüm işlemlerin kümesi.

▪ Hazır (Ready) kuyrukları - ana bellekte bulunan hazır ve yürütülmek


için bekleyenler. (CPU’ yu bekliyorlar).

▪ Aygıt (Device) kuyrukları - Bir G / Ç aygıt için bekleyen işlemlerin


kümesi.

▪ İşlemler (Processes) çeşitli kuyruklar arasında hareket ederler.

Operating System Concepts – 10th Edition 3.17 Silberschatz, Galvin and Gagne ©2018
Ready and Wait Queues

Operating System Concepts – 10th Edition 3.18 Silberschatz, Galvin and Gagne ©2018
Representation of Process Scheduling

Operating System Concepts – 10th Edition 3.19 Silberschatz, Galvin and Gagne ©2018
Context Switch
▪ When CPU switches to another process, the system must
save the state of the old process and load the saved state
for the new process via a context switch
▪ Context of a process represented in the PCB
▪ Context-switch time is pure overhead; the system does no
useful work while switching
• The more complex the OS and the PCB ➔ the longer
the context switch
▪ Time dependent on hardware support
• Some hardware provides multiple sets of registers per
CPU ➔ multiple contexts loaded at once

Operating System Concepts – 10th Edition 3.20 Silberschatz, Galvin and Gagne ©2018
Multitasking in Mobile Systems

▪ Some mobile systems (e.g., early version of iOS) allow only one
process to run, others suspended
▪ Due to screen real estate, user interface limits iOS provides for a
• Single foreground process- controlled via user interface
• Multiple background processes– in memory, running, but not
on the display, and with limits
• Limits include single, short task, receiving notification of events,
specific long-running tasks like audio playback
▪ Android runs foreground and background, with fewer limits
• Background process uses a service to perform tasks
• Service can keep running even if background process is
suspended
• Service has no user interface, small memory use

Operating System Concepts – 10th Edition 3.21 Silberschatz, Galvin and Gagne ©2018
İşlemler (Processes) ile İlgili İşlemler

▪ Sistem aşağıdakiler için mekanizmalar sağlamalıdır:

• İşlem (Process) oluşturma (creation)

• İşlem (Process) sonlandırma (termination)

Operating System Concepts – 10th Edition 3.22 Silberschatz, Galvin and Gagne ©2018
İşlem Oluşturma (Creation)

▪ Ana (Parent) işlem çocuk (children) işlemleri oluşturur, bu çocuk


işlemler de sırayla diğer işlemleri oluşturarak bir işlemler ağacı
oluştururlar.
▪ Genel olarak, işlemler, işlem tanımlayıcısı (pid) aracılığıyla
tanımlanır ve yönetilirler.
▪ Kaynak Paylaşım seçenekleri;
• Parent ve children işlemler tüm kaynakları paylaşırlar.
• Children işlemler, parent işlemlerin kaynaklarının alt kümesini
paylaşırlar.
• Parent ve children işlemler hiçbir kaynağı paylaşmazlar.
▪ Yürütme (Execution) Seçenekleri;
• Parent ve children işlemler eş zamanlı (concurrently) olarak
yürütülürler.
• Parent işlemler, children işlemler sonlanıncaya (terminate) kadar
beklerler.

Operating System Concepts – 10th Edition 3.23 Silberschatz, Galvin and Gagne ©2018
İşlem Oluşturma (Creation)
▪ Adres Alanı (Address space)
• Child işlem parent işlemin kopyasıdır. (Child duplicate of parent.)
• Child işlemin içerisine yüklenmiş bir program var. (Child has a
program loaded into it.)
▪ UNIX examples
• fork() sistem çağrısı yeni bir işlem oluşturur.
• işlemin bellek alanını yeni bir programla değiştirmek için fork ()
'dan sonra exec () sistem çağrısı kullanılır.
• Parent işlem, child işlemin sonlanması için beklerken
wait()sistem çağrısını çağırır.

Operating System Concepts – 10th Edition 3.24 Silberschatz, Galvin and Gagne ©2018
Linux’ ta İşlem Ağacı

Operating System Concepts – 10th Edition 3.25 Silberschatz, Galvin and Gagne ©2018
C Program Forking Separate Process

Operating System Concepts – 10th Edition 3.26 Silberschatz, Galvin and Gagne ©2018
Creating a Separate Process via Windows API

Operating System Concepts – 10th Edition 3.27 Silberschatz, Galvin and Gagne ©2018
İşlem Sonlandırma (Process Termination)

▪ İşlem, yapacağı görevleri tamamladığında durarak, işletim sistemine


“çıkış sistem çağrısı” nı kullanarak durdurulması gerektiğini bildirir
(exit()).
• Child işlemden parent işleme verilerin durumu döndürülerek (wait() komutu ile).

• Child işlemin kullandığı kaynaklar işletim sistemi tarafından geri alınarak.

▪ Parent abort() komutunu kullanarak child işlemin yürütülmesini


sonlandırabilir. (Process id ile)
• Child işlem, kendisine tahsis edilen kaynakları aştığı durumlarda,

• Child işleme atanan görevin yürütülmesine ihtiyaç kalmadığı durumlarda,

• Parent işlem sonlandığında, işletim sistemi ilgili parent’ ın child işleminin devam
etmesine izin vermediği durumlarda.

Operating System Concepts – 10th Edition 3.28 Silberschatz, Galvin and Gagne ©2018
İşlem Sonlandırma (Process Termination)
▪ Bazı işletim sistemleri, parent işlem sonlandıysa child işlemin var
olmasına izin vermez. Bir işlem sona ererse, tüm alt işlemleri de
sonlandırılmalıdır.
▪ Basamaklı Sonlandırma (cascading termination): Tüm children,
grandchildren, vb. işlemler sonlandırılmalıdır.
▪ Sonlandırma (termination) işlemi işletim sistemi tarafından başlatılır.
▪ Parent işlem wait() sistem çağrısını kullanarak bir alt işlemin
sonlandırılmasını bekleyebilir. Çağrı, durum bilgisini ve sonlandırılan
işlemin pid‘ sini döndürür
▪ pid = wait(&status);
▪ If no parent waiting (did not invoke wait()) process is a zombie
▪ If parent terminated without invoking wait(), process is an orphan
▪ Bir child işlemin parent’ ı sonlanmışsa bu işleme orphan işlem denir.

Operating System Concepts – 10th Edition 3.29 Silberschatz, Galvin and Gagne ©2018
Android İşlem Önemlilik Hiyerarşisi

▪ Mobil işletim sistemleri genellikle bellek gibi sistem kaynaklarını geri


kazanmak için işlemleri sonlandırmak zorundadır.

▪ En önemliden daha az önemliye doğru:

• Ön plan İşlemleri - Foreground process

• Görünür İşlemler - Visible process

• Servis İşlemleri - Service process

• Arkaplan İşlemler - Background process

• Boş İşlemler - Empty process

▪ Android, en az önemli olan işlemleri sonlandırmaya başlayacaktır.

Operating System Concepts – 10th Edition 3.30 Silberschatz, Galvin and Gagne ©2018
Multiprocess Mimari – Chrome Browser

▪ Birçok web tarayıcısı tek bir işlem olarak çalışmaktaydı.


• Bir web sitesi soruna neden olursa, tarayıcının tamamı kilitlenebilir
veya çökebilir
▪ Google Chrome Tarayıcı, 3 farklı işlem türü ile çok işlemlidir:
• Browser process - Tarayıcı işlemi, kullanıcı arayüzünü, diski ve ağ
G / Ç‘ ı yönetir
• Renderer process - Oluşturucu işlemi, web sayfalarını işler, HTML,
Javascript ile ilgilenir. Açılan her web sitesi için yeni bir oluşturucu
oluşturulur.
 Güvenlik açıklarının etkisini en aza indirerek, disk ve ağ G / Ç‘ ı
kısıtlayan korumalı alanda çalışır.
• Plug-in process: Her eklenti türü için eklenti süreişlemi.

Operating System Concepts – 10th Edition 3.31 Silberschatz, Galvin and Gagne ©2018
İşlemler Arası İletişim - Interprocess Communication

▪ İşletim sistemindeki işlemler bağımsız (independent) veya işbirliği


halinde (cooperating) olmak üzere iki şekilde faaliyet gösterirler.
▪ İşbirliği süreci, veri paylaşımı dahil diğer işlemleri etkileyebilir veya
bunlardan etkilenebilir
▪ İşbirliği işlemlerinin sistemde kullanılmasının birçok nedeni vardır;
• Bilgi Paylaşımı - Information sharing
• İşlem Hızı - Computation speedup
• Modülerlik - Modularity
• Rahatlık - Convenience
▪ İşbirliği halindeki işlemlerin interprocess communication (IPC)
yapısına ihtiyaçları vardır.
▪ IPC için iki farklı model vardır;
• Paylaşılan Bellek - Shared memory
• Mesaj Geçişi - Message passing

Operating System Concepts – 10th Edition 3.32 Silberschatz, Galvin and Gagne ©2018
İletişim Modelleri
(a) Shared memory. (b) Message passing.

Operating System Concepts – 10th Edition 3.33 Silberschatz, Galvin and Gagne ©2018
Üretici-Tüketici Problemi / Producer-Consumer
Problem

▪ İşbirliği işlemleri için bir paradigma:


• Üretici işlemi, bir tüketici işlemi tarafından tüketilen bilgileri üretir.
▪ İki farklı yapı:
• unbounded-buffer / sınırsız buffer, buffer boyutuna pratik bir
sınır koymaz:
 Producer / Üretici asla beklemez.
 Consumer / Tüketici, tüketilecek bir buffer yoksa bekler.
• bounded-buffer / sınırlı arabellek, sabit bir buffer boyutu
olduğunu varsayar
 Producer / Üretici tüm buffer alanları doluysa bekler.
 Consumer / Tüketici, tüketilecek bir buffer yoksa bekler.

Operating System Concepts – 10th Edition 3.34 Silberschatz, Galvin and Gagne ©2018
Bounded-Buffer – Shared-Memory Solution

▪ 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 BUFFER_SIZE-1 elements

Operating System Concepts – 10th Edition 3.35 Silberschatz, Galvin and Gagne ©2018
Buffer State in Shared Memory

Operating System Concepts – 10th Edition 3.36 Silberschatz, Galvin and Gagne ©2018
Buffer State in Shared Memory

Operating System Concepts – 10th Edition 3.37 Silberschatz, Galvin and Gagne ©2018
Producer Process – Shared Memory

item next_produced;

while (true) {
/* produce an item in next produced */
while (((in + 1) % BUFFER_SIZE) == out)
; /* do nothing */
buffer[in] = next_produced;
in = (in + 1) % BUFFER_SIZE;
}

Operating System Concepts – 10th Edition 3.38 Silberschatz, Galvin and Gagne ©2018
Consumer Process – Shared Memory

item next_consumed;

while (true) {
while (in == out)
; /* do nothing */
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;

/* consume the item in next consumed */


}

Operating System Concepts – 10th Edition 3.39 Silberschatz, Galvin and Gagne ©2018
IPC – Paylaşılan Bellek/Shared Memory

▪ İletişim kurmak isteyen işlemler arasında paylaşılan bir hafıza


alanıdır.

▪ İletişim, işletim sisteminin değil kullanıcıların işlemlerinin kontrolü


altındadır.

▪ Mekanizmasnın sağlaması gereken, kullanıcı işlemlerinin


paylaşılan belleğe eriştiklerinde eylemlerini senkronize etmelerine
izin vermesidir.

▪ Senkronizasyon, Bölüm 6 ve 7'de ayrıntılarla ele alınacaktır.

Operating System Concepts – 10th Edition 3.40 Silberschatz, Galvin and Gagne ©2018
Tüm Tamponları (Buffer Alanlarını) Doldurmaya ne dersiniz?

▪ Tüketici-üretici sorununa tüm tamponları dolduran bir çözüm sunmak


istediğimizi varsayalım.

▪ Bunu, tam arabelleklerin sayısını takip eden bir tamsayı sayacı


kullanarak yapabiliriz.

▪ Başlangıçta sayaç 0 olarak ayarlanmıştır.

▪ Tam sayı sayacı, yeni bir tampon oluşturduktan sonra üretici


tarafından artırılır.

▪ Tam sayı sayacı, bir tampon tükettikten sonra tüketici tarafından


azaltılı.

Operating System Concepts – 10th Edition 3.41 Silberschatz, Galvin and Gagne ©2018
Producer

while (true) {
/* produce an item in next produced */

while (counter == BUFFER_SIZE)


; /* do nothing */
buffer[in] = next_produced;
in = (in + 1) % BUFFER_SIZE;
counter++;
}

Operating System Concepts – 10th Edition 3.42 Silberschatz, Galvin and Gagne ©2018
Consumer

while (true) {
while (counter == 0)
; /* do nothing */
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
counter--;
/* consume the item in next consumed */
}

Operating System Concepts – 10th Edition 3.43 Silberschatz, Galvin and Gagne ©2018
Race Condition
▪ counter++ could be implemented as
register1 = counter
register1 = register1 + 1
counter = register1
▪ counter-- could be implemented as
register2 = counter
register2 = register2 - 1
counter = register2

▪ Consider this execution interleaving with “count = 5” initially:


S0: producer execute register1 = counter {register1 = 5}
S1: producer execute register1 = register1 + 1 {register1 = 6}
S2: consumer execute register2 = counter {register2 = 5}
S3: consumer execute register2 = register2 – 1 {register2 = 4}
S4: producer execute counter = register1 {counter = 6 }
S5: consumer execute counter = register2 {counter = 4}

Operating System Concepts – 10th Edition 3.44 Silberschatz, Galvin and Gagne ©2018
Race Condition (Cont.)
▪ Question – why was there no race condition
in the first solution (where at most N – 1)
buffers can be filled?
▪ More in Chapter 6.

Operating System Concepts – 10th Edition 3.45 Silberschatz, Galvin and Gagne ©2018
IPC – Mesaj Geçişi / Message Passing

▪ Süreçler arasında mesaj gönderip, almak için send ve receive


şeklinde iki sistem çağrısı bulunur. messages
passed
• send(message) through
• receive(message)
P Q
▪ Mesaj boyutu sabit veya değişkendir.

▪ P ve Q işlemleri iletişim kurmak isterse, şunları yapmaları gerekir: Logical


• Aralarında bir iletişim bağlantısı kurulmalıdır. Communication
• Gönderme / Alma yoluyla mesaj alışverişi gerçekleştirilmelidir. Link

Operating System Concepts – 10th Edition 3.46 Silberschatz, Galvin and Gagne ©2018
İletişim Modelleri
(a) Shared memory. (b) Message passing.

Operating System Concepts – 10th Edition 3.47 Silberschatz, Galvin and Gagne ©2018
Mesaj Geçişi / Message Passing

▪ Uygulama sorunları:

• Bağlantılar (Links) nasıl kurulur?

• Bir bağlantı ikiden fazla işlemle ilişkilendirilebilir mi?

• Her bir iletişim işlemi çifti arasında kaç bağlantı olabilir?

• Bir bağlantının kapasitesi nedir?

• Bağlantının barındırabileceği mesajın boyutu sabit mi yoksa


değişken midir?

• Bir bağlantı tek yönlü mü yoksa çift yönlü müdür?

Operating System Concepts – 10th Edition 3.48 Silberschatz, Galvin and Gagne ©2018
Doğrudan Haberleşme / Direct Communication

▪ İşlemler birbirlerini açıkça (explicitly) adlandırmalıdır:


• send (P, message) – P işlemine bir mesaj gönderin
• receive(Q, message) – Q işleminden bir mesaj alın

▪ İletişim bağlantısının özellikleri;


• Bağlantılar otomatik olarak kurulur.
• Bir bağlantı, tam olarak bir çift iletişim işlemi ile ilişkilidir.
• Her çift arasında tam olarak bir bağlantı vardır.
• Bağlantı tek yönlü olabilir, ancak genellikle iki yönlüdür.

Operating System Concepts – 10th Edition 3.49 Silberschatz, Galvin and Gagne ©2018
Dolaylı Haberleşme / Indirect Communication

▪ Mesajlar posta kutularından yönlendirilir ve alınırlar (bağlantı


noktaları olarak da adlandırılır).
• Her posta kutusunun benzersiz bir kimliği vardır.
• İşlemler yalnızca bir posta kutusunu paylaşırlarsa iletişim
kurabilirler.

▪ İletişim bağlantısının özellikleri;


• Bağlantı yalnızca işlemler ortak bir posta kutusunu paylaşıyorsa
kurulur.
• Bir bağlantı birçok işlemle ilişkilendirilebilir.
• Her işlem çifti birkaç iletişim bağlantısını paylaşabilir.
• Bağlantı tek yönlü veya çift yönlü olabilir.

Operating System Concepts – 10th Edition 3.50 Silberschatz, Galvin and Gagne ©2018
Dolaylı Haberleşme / Indirect Communication

▪ İşlemler / Operations
• Yeni bir posta kutusu (bağlantı noktası) oluşturulması.
• Posta kutusu aracılığıyla mesaj gönderiminin ve alımının
gerçekleştirilmesi
• Posta kutusunun silinmesi.
▪ Temel olarak şu şekilde tanımlanır;
• send(A, message) – A posta kutusuna bir mesaj gönder.
• receive(A, message) – A posta kutusundan bir mesaj al.

Operating System Concepts – 10th Edition 3.51 Silberschatz, Galvin and Gagne ©2018
Dolaylı Haberleşme / Indirect Communication

▪ Posta kutusu paylaşımı;


• P1, P2, ve P3 A posta kutusunu paylaşıyorlar
• P1, mesaj gönderdi; P2 ve P3 mesajı alabilir.
• Mesajı kim alacak?
▪ Çözümler;
• Bir bağlantının en fazla iki işlemle ilişkilendirilmesine izin vermek.
• Bir alma işlemini yürütmek için aynı anda yalnızca bir işleme izin
vermek.
• Sistemin rastgele alıcıyı seçmesine izin verip, gönderene, alıcının
kim olduğu bildirmek..

Operating System Concepts – 10th Edition 3.52 Silberschatz, Galvin and Gagne ©2018
Senkronizasyon (Synchronization)
Mesaj Geçişi (Message passing) engellemeli (blocking) ya da
engellemesiz (non-blocking) olmak üzere iki farklı şekilde olabilir.
▪ Engellemeli (Blocking), eş zamanlı, senkron (synchronous) olarak
kabul edilir.
• Blocking send -- gönderen, mesaj alınana kadar engellenir.
• Blocking receive -- alıcı bir mesaj mevcut olana kadar engellenir.
▪ Engellemesiz (Non-blocking), eş zamansız, asenkron (asynchronous)
olarak kabul edilir.
• Non-blocking send -- gönderen mesajı gönderir ve devam eder
• Non-blocking receive -- alıcı şunları alır:
 Geçerli bir mesaj (A valid message), ya da
 Boş (Null) mesaj
▪ Farklı kombinasyonlar mümkündür.
• Hem gönderme hem de alma engelliyse, bir randevu (rendezvous)
vardır.

Operating System Concepts – 10th Edition 3.53 Silberschatz, Galvin and Gagne ©2018
Ara Belleğe Alma (Buffering)

▪ Bağlantıya eklenen mesajların sırası.

▪ Üç yoldan biriyle uygulanır;

1. Zero capacity – Sıfır kapasite: bağlantıda hiçbir ileti sıraya alınmaz.


Gönderenin alıcıyı beklemesi gerekir (randevu-rendezvous).

2. Bounded capacity – Sınırlı kapasite - n mesajın sonlu uzunluğu


Gönderici, bağlantı doluysa beklemelidir.

3. Unbounded capacity – Sınırsız kapasite - sonsuz uzunluk


Gönderici asla beklemez.

Operating System Concepts – 10th Edition 3.54 Silberschatz, Galvin and Gagne ©2018
Producer-Consumer: Message Passing

▪ Producer
message next_produced;
while (true) {
/* produce an item in next_produced */

send(next_produced);
}

▪ Consumer
message next_consumed;
while (true) {
receive(next_consumed)

/* consume the item in next_consumed */


}

Operating System Concepts – 10th Edition 3.55 Silberschatz, Galvin and Gagne ©2018
Examples of IPC Systems - POSIX

▪ POSIX Shared Memory


• Process, ilk olarak paylaşılan bellek bölümünü oluşturur. Ayrıca
mevcut bir segmenti açmak için de kullanılır.
• shm_fd = shm_open(name, O CREAT | O RDWR, 0666);
• shm_unlink
• Paylaşılan bellek alanının (nesnenin) boyutunun belirlenmesi için;
ftruncate(shm_fd, 4096);
• mmap() :Bir dosya işaretçisini paylaşılan bellek nesnesine eşlemek
için kullanılır.
• Paylaşılan belleğe okuma ve yazma, mmap () tarafından döndürülen
pointer (işaretçi) kullanılarak yapılır.

Operating System Concepts – 10th Edition 3.56 Silberschatz, Galvin and Gagne ©2018
IPC POSIX Producer

Operating System Concepts – 10th Edition 3.57 Silberschatz, Galvin and Gagne ©2018
IPC POSIX Consumer

Operating System Concepts – 10th Edition 3.58 Silberschatz, Galvin and Gagne ©2018
Examples of IPC Systems - Mach
▪ Mach communication is message based
• Even system calls are messages
• Each task gets two ports at creation - Kernel and Notify
• Messages are sent and received using the mach_msg() function
• Ports needed for communication, created via
mach_port_allocate()
• Send and receive are flexible; for example four options if mailbox
full:
 Wait indefinitely
 Wait at most n milliseconds
 Return immediately
 Temporarily cache a message

Operating System Concepts – 10th Edition 3.59 Silberschatz, Galvin and Gagne ©2018
Mach Messages

#include<mach/mach.h>

struct message {
mach_msg_header_t header;
int data;
};

mach port t client;


mach port t server;

Operating System Concepts – 10th Edition 3.60 Silberschatz, Galvin and Gagne ©2018
Mach Message Passing - Client

Operating System Concepts – 10th Edition 3.61 Silberschatz, Galvin and Gagne ©2018
Mach Message Passing - Server

Operating System Concepts – 10th Edition 3.62 Silberschatz, Galvin and Gagne ©2018
Examples of IPC Systems – Windows

▪ Message-passing centric via advanced local procedure call


(LPC) facility
• Only works between processes on the same system
• Uses ports (like mailboxes) to establish and maintain
communication channels
• Communication works as follows:
 The client opens a handle to the subsystem’s
connection port object.
 The client sends a connection request.
 The server creates two private communication ports
and returns the handle to one of them to the client.
 The client and server use the corresponding port handle
to send messages or callbacks and to listen for replies.

Operating System Concepts – 10th Edition 3.63 Silberschatz, Galvin and Gagne ©2018
Local Procedure Calls in Windows

Operating System Concepts – 10th Edition 3.64 Silberschatz, Galvin and Gagne ©2018
Pipes

▪ Acts as a conduit allowing two processes to communicate


▪ Issues:
• Is communication unidirectional or bidirectional?
• In the case of two-way communication, is it half or full-duplex?
• Must there exist a relationship (i.e., parent-child) between the
communicating processes?
• Can the pipes be used over a network?
▪ Ordinary pipes – cannot be accessed from outside the process that
created it. Typically, a parent process creates a pipe and uses it to
communicate with a child process that it created.
▪ Named pipes – can be accessed without a parent-child relationship.

Operating System Concepts – 10th Edition 3.65 Silberschatz, Galvin and Gagne ©2018
Ordinary Pipes
▪ Ordinary Pipes allow communication in standard producer-consumer
style
▪ Producer writes to one end (the write-end of the pipe)
▪ Consumer reads from the other end (the read-end of the pipe)
▪ Ordinary pipes are therefore unidirectional
▪ Require parent-child relationship between communicating processes

▪ Windows calls these anonymous pipes

Operating System Concepts – 10th Edition 3.66 Silberschatz, Galvin and Gagne ©2018
Named Pipes

▪ Named Pipes are more powerful than ordinary pipes


▪ Communication is bidirectional
▪ No parent-child relationship is necessary between the communicating
processes
▪ Several processes can use the named pipe for communication
▪ Provided on both UNIX and Windows systems

Operating System Concepts – 10th Edition 3.67 Silberschatz, Galvin and Gagne ©2018
Client-Server Sistemlerinde Haberleşme

▪ Soketler (Sockets)

▪ Uzaktan İşlem Çağrısı (Remote Procedure Calls)

Operating System Concepts – 10th Edition 3.68 Silberschatz, Galvin and Gagne ©2018
Soketler

▪ Soket (Socket), iletişim için bir uç nokta olarak tanımlanır

▪ Concatenation of IP address and port – IP adresinin ve bağlantı


noktasının birleştirilmesi: bir ana bilgisayardaki ağ hizmetlerini ayırt
etmek için mesaj paketinin başlangıcına eklenen bir sayı.

▪ 161.25.19.8:1625 numaralı soket, 161.25.19.8 numaralı adrese sahip


ana bilgisayar üzerindeki 1625 numaralı bağlantı noktasına başvurur.
İletişim bir çift soket arasında gerçekleşir.

▪ 1024'ün altındaki tüm bağlantı noktaları iyi bilinir ve standart hizmetler


için kullanılır

▪ İşlemin çalıştığı sistemi ifade etmek için özel IP adresi 127.0.0.1 (geri
döngü) kullanılır.

Operating System Concepts – 10th Edition 3.69 Silberschatz, Galvin and Gagne ©2018
Soket Haberleşme

Operating System Concepts – 10th Edition 3.70 Silberschatz, Galvin and Gagne ©2018
Java’ da Soketler

▪ Üç tip soket vardır.


• Connection-oriented
(TCP)
• Connectionless (UDP)
• MulticastSocket
class– data birden çok
alıcıya gönderilebilir
• Consider this “Date”
server in Java:

Operating System Concepts – 10th Edition 3.71 Silberschatz, Galvin and Gagne ©2018
Java’ da Soketler
The equivalent Date client

Operating System Concepts – 10th Edition 3.72 Silberschatz, Galvin and Gagne ©2018
Remote Procedure Calls

▪ Remote procedure call (RPC) / Uzaktan yordam çağrısı (RPC), ağa


bağlı sistemlerdeki işlemler arasında prosedür çağrılarını özetler

• Servis farklılaştırması için bağlantı noktaları (ports) kullanılır.

▪ Stubs – sunucudaki gerçek prosedür için istemci tarafı proxy

▪ İstemci tarafı stub, sunucuyu bulur ve parametreleri düzenler.

▪ Sunucu tarafındaki stub bu mesajı alır, sıralanan parametreleri


paketten çıkarır ve sunucuda prosedürü gerçekleştirir.

▪ Windows'ta, stub kodu Microsoft Arayüz Tanım Dili'nde / Microsoft


Interface Definition Language (MIDL) yazılmış spesifikasyonlardan
derlenir

Operating System Concepts – 10th Edition 3.73 Silberschatz, Galvin and Gagne ©2018
Remote Procedure Calls

▪ Farklı mimarileri hesaba katmak için External Data Representation


(XDL) Harici Veri Gösterimi (XDL) formatı aracılığıyla işlenen veri
temsili.

• Big-endian ve little-endian

▪ Uzaktan iletişim, yerelden daha fazla hata senaryosuna sahiptir

• Mesajlar en fazla bir kez değil, tam olarak bir kez teslim edilebilir

▪ İşletim sistemi genellikle istemci ve sunucu arasında bağlantı kurmak


için bir buluşma (veya eşleştirme) hizmeti sağlar

Operating System Concepts – 10th Edition 3.74 Silberschatz, Galvin and Gagne ©2018
RPC’ nin Yürütülmesi

Operating System Concepts – 10th Edition 3.75 Silberschatz, Galvin and Gagne ©2018
End of Chapter 3

Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Producer-Consumer Problem

▪ Paradigm for cooperating processes:


• producer process produces information that is consumed
by a consumer process
▪ Two variations:
• unbounded-buffer places no practical limit on the size of
the buffer:
 Producer never waits
 Consumer waits if there is no buffer to consume
• bounded-buffer assumes that there is a fixed buffer size
 Producer must wait if all buffers are full
 Consumer waits if there is no buffer to consume

Operating System Concepts – 10th Edition 3.77 Silberschatz, Galvin and Gagne ©2018
Cooperating Processes

▪ Independent process cannot affect or be affected by the execution


of another process
▪ Cooperating process can affect or be affected by the execution of
another process
▪ Advantages of process cooperation
• Information sharing
• Computation speed-up
• Modularity
• Convenience

Operating System Concepts – 10th Edition 3.78 Silberschatz, Galvin and Gagne ©2018
Synchronization
▪ Message passing may be either blocking or non-blocking
• Blocking is considered synchronous
 Blocking send -- the sender is blocked until the message is
received
 Blocking receive -- the receiver is blocked until a message is
available
• Non-blocking is considered asynchronous
 Non-blocking send -- the sender sends the message and
continue
 Non-blocking receive -- the receiver receives:
 A valid message, or
 Null message
• Different combinations possible
 If both send and receive are blocking, we have a rendezvous

Operating System Concepts – 10th Edition 3.79 Silberschatz, Galvin and Gagne ©2018

You might also like