Upload
others
View
16
Download
0
Embed Size (px)
Citation preview
1
Silberschatz, Galvin and Gagne 2002 3.1 Operating System Concepts
İşletim Sistemi Yapıları
Sistem Bileşenleri
İşletim Sistemi Hizmetleri
Sistem Çağrıları
Sistem Programları
Sistem Yapısı
Sanal Makine
Sistemi Tasarımı ve Uygulaması
Sistem Üretimi
Silberschatz, Galvin and Gagne 2002 3.2
Uygulama yazılımı, Sistem yazılımı ve
İşletim Sistemi
Silberschatz, Galvin and Gagne 2002 3.3
Performans:
İşletim sistemi, makine kaynaklarını (özellikle MİB zamanı
ve bellek alanı) en etkili şekilde kullanılmasını sağlayacak
şekilde tasarlanmalıdır.
Kaynakların özel kullanımı:
İşletim sistemi, kaynakların yalıtımını sağlamalıdır,
Bir işlemin diğer işleme ait kaynaklara olan
müdahalesine veya bu işleme ait bilgilerin silinmesine
izin vermeyen bir koruma mekanizması geliştirmelidir.
Bir işletim sisteminin yazılım tasarımında ele
alınması gereken iki önemli konu bulunmaktadır;
Silberschatz, Galvin and Gagne 2002 3.4
Her işletim sisteminin
tasarımında olan üç temel
unsur ise şunlardır;
İşlemci modları
Çekirdek (Kernel)
Sistem servislerini uyarma metodu
Silberschatz, Galvin and Gagne 2002 3.5
İşlemci Modları
Supervisor Mod (Kernel Mod):
İşlemci supervisor modda iken donanımsal her tür komutu
çalıştırır.
Supervisor moda çalışan komutlara öncelikli komutlar
denilmektedir.
Kullanıcı Modu:
İşletim sistemi programları supervisor moda çalışırken
diğer tüm yazılımlar kullanıcı modunda çalışmaktadır.
Örneğin giriş/çıkış işlemleri supervisor moda çalışmakta,
kullanıcı modunda yer alan bir program herhangi bir
giriş/çıkış işlemi yapılmasını istediğinde bunu işletim
sisteminin yapmasını istemektedir.
Silberschatz, Galvin and Gagne 2002 3.6
İşlemci Modları – Bellek Kullanımı
Kullanıcı
Alanı
Supervisor
Alanı
Kullanıcı
İşlemleri
Supervisor
İşlemleri
2
Silberschatz, Galvin and Gagne 2002 3.7
Supervisor Çağrı (Supervisor Call)
İşlemci supervisor moda geçtiğinde işletim
sisteminin kodlarını çalıştırmaktadır.
Kullanıcı modundaki bir işlem işletim
sistemini çağırdığında işlemci hemen
supervisor moda, mod bitini kullanarak
geçer ki bu duruma supervisor çağrı (veya
sistem çağrısı) denilmektedir.
Silberschatz, Galvin and Gagne 2002 3.8
Supervisor Çağrı (Supervisor
Call – System Call)
Örneğin; Word’de büyük bellek gerektiren bir dosya açınca
başka işlemlerin alanlarına müdahale edilir. Bunu önlemek
amacıyla yeni bir alan bu dosya için eklenmelidir. Burada
supervisor çağrı yapılmıştır.
Silberschatz, Galvin and Gagne 2002 3.9
Çekirdek
İşletim sisteminin supervisor modda çalışan ve diğer parçaları için temel servisleri sağlayan en önemli parçasıdır.
İşletim sisteminin uzantıları kullanıcı modunda çalışır ve daha sınırlı haklara sahip olur.
Çekirdekte çalışan işletim sistemi fonksiyonları ise belleğe ve çekirdeğin diğer bölümlerine ulaşmada daha fazla haklara sahiptir.
Silberschatz, Galvin and Gagne 2002 3.10
Kabuk (Shell) - Komut
yorumlayıcısı (Command Line
Interpreter) Kabuk (shell) veya diğer adıyla komut
yorumlayıcısı ise kullanıcının sisteme verdiği
komutları anlayan ve çalıştıran bir programdır.
Kabuğun genellikle bir arayüzü
bulunmaktadır; örneğin DOS’taki C:> nin
göründüğü komut istemi arayüzü ve
kullanıcının girdiği DIR komutu.
Çekirdek ve kabuk bazı işletim sistemlerinde
ayrı iken bazılarında da sadece kavramsal
olarak ayrılmıştır.
Silberschatz, Galvin and Gagne 2002 3.11
Kabuk
programı
Kabuk (Shell) - Komut
yorumlayıcısı (Command Line
Interpreter)
Uygulama ve
Sistem
Yazılımları
İşletim Sistemi Sistem Çağrı Arayüzü
İşletim Sistemi
Kullanıcı
Silberschatz, Galvin and Gagne 2002 3.12
Çekirdek türleri
Monolitik çekirdekler (monolithic kernel):
1970–1990 arasında kullanılan ilk çekirdeklerdir. Burada
tüm yazılımlar, sürücüler işletim sisteminin çekirdeğinde
yer almaktadır. Boyutu büyüktür.
Örn: Unix
Mikro çekirdekler (microkernel):
Modüler yapısı olan bu çekirdeklerde sadece en önemli
işletim sistemi fonksiyonları bulunmakta ve oldukça küçük
boyuttadır.
Yeni bir donanım eklendiğinde onun sürücüsü de
çekirdeğe tanıtılmaktadır.
Örn: MS-DOS
3
Silberschatz, Galvin and Gagne 2002 3.13
Sistem servislerini uyarma
metodu
Kullanıcı işlemlerinin işletim sisteminden belli
servisleri (program çalıştırma, giriş/çıkış ve
dosya işlemleri, ağ erişimi gibi) sağlaması
istendiğinde oluşan bir durumdur.
Bu bir sistem fonksiyonunun çağrılması veya
MİB’ne bir mesaj gönderilmesi ile
gerçekleşmektedir.
Silberschatz, Galvin and Gagne 2002 3.14
Sistem servislerini uyarma
metodu
Sistem çağrıları, işletim sistemi ve işlemler arasında bir
arayüzdür.
Bu çağrılar genellikle Assembly dili komutları
şeklindedir. C ve C++ gibi bazı programlama dilleri
bunu direkt olarak yapabilmektedir.
Microsoft Windows ise bunu Win32 API ile
gerçekleştirir.
Silberschatz, Galvin and Gagne 2002 3.15
Temel İşletim Sistemi Katmanları
Uygulama Katmanı
Kabuk (Shell) Katmanı
Çekirdek (Kernel) Katmanı
Donanım Katmanı
Silberschatz, Galvin and Gagne 2002 3.16
UNIX İşletim Sistemi Katmanları
Sü
rücü
Ara
yü
zü
Monolitik Çekirdek Modülleri
İşlem yönetimi Bellek yönetimi
Dosya yönetimi Aygıt yönetimi
altyapısı
Sistem çağrı arayüzü
Kütüphaneler Komutlar Uygulama
Programları
Sürücü
Sürücü
Sürücü
Donanım Katmanı
Silberschatz, Galvin and Gagne 2002 3.17
Windows NT/2000/XP İşletim
Sistemi Katmanları
İşlemci Ana Bellek Aygıtlar
NT Yürütücüsü (Executive)
Kütüphaneler İşlem
Supervi
sor
İşlem yönetimi
Bellek yönetimi
Dosya yönetimi
Aygıt yönetimi
altyapısı
G/Ç Alt
sistemi
Nt Çekirdeği
Donanım Soyutlama
Katmanı
Kullanıcı Altsistem
Silberschatz, Galvin and Gagne 2002 3.18 Operating System Concepts
İşletim Sistemi Hizmetleri
Program yürütme - belleğe bir program yüklemek ve
çalıştırmak için sistemi yeteneği.
I / O işlemleri - kullanıcı programları doğrudan I / O
operasyonları yürütmek mümkün olmadığı, işletim
sisteminin I / O gerçekleştirmek için bazı araçlar
sağlamak gerekir
Dosya-sistem işlemleri - program yeteneği, okuma,
yazma, oluşturma ve dosyaları silmek için.
İletişim - aynı bilgisayarda veya bir ağ ile birbirine bağlı
farklı sistemlerde ya yürütme süreçler arasında bilgi
alışverişi. Paylaşılan bellek veya mesaj vermek üzerinden
uygulanmaktadır.
Hata algılama - I / O cihazları, ya da kullanıcı programları,
CPU ve bellek donanım hataları tespit ederek doğru
hesaplama yapar.
4
Silberschatz, Galvin and Gagne 2002 3.19 Operating System Concepts
Ek İşletim Sistemi Fonksiyonları
İlave fonksiyonlar değildir, verimli sistem
operasyonları sağlanması içindir, kullanıcıya
yardımcı olmak için mevcut değildir.
Kaynak tahsisi – Bazı zamanlarda çalışan
birden fazla kullanıcı veya birden fazla iş için
kaynak ayırmak.
Muhasebe - Kullanıcıların ne kadar kullanmak
ve hangi hesap için fatura ya da kullanım
istatistikleri biriktirme bilgisayar kaynaklarının
türlü hangi takip ve kayıt tutmak.
Koruma - sistem kaynaklarına bütün erişim
kontrol edilir sağlanması.
Silberschatz, Galvin and Gagne 2002 3.20 Operating System Concepts
Sistem Çağrıları
Sistemi arasında arayüz çalışan bir program ve işletim sistemi
çağrılarını sağlar.
Montaj-dili(assembly-language) talimatları genel olarak kullanılabilir.
Sistem programlama için Assembly dili yerine tanımlanan Diller sistemi
doğrudan (örneğin, C, C + +) yapılacak aramalara izin verir
Üç genel yöntemler çalışan bir program ve işletim sistemi arasında
parametre geçirmek için kullanılır
Yazmaçlarda parametreler.
Hafızada bir tablosundaki parametrelerin saklamak ve tablo
adresi bir kayıt bir parametre olarak geçirilir.
Program tarafından (mağaza) yığına parametreleri itin ve işletim
sistemi tarafından yığından pop
Üç en yaygın API'ler Java sanal makinesi (JVM) için Windows, POSIX
tabanlı sistemler (UNIX, Linux ve Mac OS X neredeyse tüm sürümleri
de dahil olmak üzere) için POSIX API ve Java API için Win32 API,
Silberschatz, Galvin and Gagne 2002 3.21 Operating System Concepts
Tabloda Parametrelerin Geçişi:
Silberschatz, Galvin and Gagne 2002 3.22 Operating System Concepts
Sistem Çağrıları Türleri
Proses Kontrol
Dosya Yönetimi
Aygıt Yönetimi
Bakım Bilgileri
İletişim
Silberschatz, Galvin and Gagne 2002 3.23 Operating System Concepts
MS-DOS Yürütme
Sistemde başlamak Bir Programı Çalıştırmak
Silberschatz, Galvin and Gagne 2002 3.24 Operating System Concepts
UNIX Çalışan Birden Çok Programlar
5
Silberschatz, Galvin and Gagne 2002 3.25 Operating System Concepts
İletişim Modelleri
Msg Geçişi Paylaşılan bellek
İletişim mesaj vermek ya da paylaşımlı bellek kullanarak yer
alabilir.
Silberschatz, Galvin and Gagne 2002 3.26 Operating System Concepts
Sistem Programları
Sistem programları, program geliştirme ve çalıştırma için
uygun bir ortam sağlar,Ayrılabilirler.
Dosya Manipülasyon
Durum Bilgisi
Dosya Değişiklik
Programlama Dili Desteği
Program yükleme ve yürütme
İletişim
Uygulama programları
Kullanıcıların çoğu’ daki operasyonun sistem tarafından
tanımlanmış sistem programları değil, gerçek sistem
çağrılarıdır.
Silberschatz, Galvin and Gagne 2002 3.27 Operating System Concepts
MS-DOS Sistem Yapısı
MS-DOS – en çok işlevselliği en az
alanda sağlar
Modüllere ayrılmamıştır
MS-DOS bazı yapılara sahip olmasına
rağmen, arayüz yapısı ve
fonksiyonellik düzeyleri çok iyi değildir.
Silberschatz, Galvin and Gagne 2002 3.28 Operating System Concepts
MS-DOS Katmanlı Yapısı
Silberschatz, Galvin and Gagne 2002 3.29 Operating System Concepts
UNIX Sistem Yapısı
UNIX – donanımın yapısına göre sınırlı bir
yapısı vardır.UNIX işletim sistemini iki parçaya
ayırabiliriz.
Sistem Programları
Kernel
Sistem çağrı arayüzü altında ve fiziksel
donanım üzerinde herşeyi içerir.
Dosya sistemi, CPU zamanlaması, bellek
yönetimi ve diğer işletim sistemi
fonksiyonlarını sağlar; bir seviye için çok
sayıda fonksiyon sağlar.
Silberschatz, Galvin and Gagne 2002 3.30 Operating System Concepts
UNIX Sistem Yapısı
6
Silberschatz, Galvin and Gagne 2002 3.31 Operating System Concepts
Katmanlı Yaklaşım
İşletim Sistemi bir dizi katmanlara ayrılmıştır ve her bir
yapı bir alt katmanın üzerine inşa edilir.En alt katman
(katman 0), donanım; en yükseği (katman N) ise kullanıcı
arayüzüdür.
Katmanlar, her türlü fonksiyonları(işlemleri) kullanabilir
ama sadece alt düzey katmanların hizmetlerini
kullanabilir.
Silberschatz, Galvin and Gagne 2002 3.32 Operating System Concepts
Bir İşletim Sisteminin Katmanı
Silberschatz, Galvin and Gagne 2002 3.33 Operating System Concepts
OS/2 Katmanlı Yapısı
Silberschatz, Galvin and Gagne 2002 3.34 Operating System Concepts
Microkernel Sistem Yapısı
Kernel’den başlayıp “kullanıcı” alanına kadar uzanır.
İletişim kullanıcı modülleri arasında yer alır ve mesaj
yollamayı sağlar.
Yararları:
- microkerneli genişletmek daha basit
- yeni mimarileri işletim sistemine uyumlu hale
getirmek daha basit
- daha güvenilir (çekirdek modunda daha az kod
çalışıyor)
- daha güvenli
Silberschatz, Galvin and Gagne 2002 3.35 Operating System Concepts
Windows NT İstemci-Sunucu Yapısı
Silberschatz, Galvin and Gagne 2002 3.36 Operating System Concepts
Sanal Makineler
Bir sanal makine kendi mantıksal sonucuna katmanlı
bir yaklaşım getiriyor. Donanım ve işletim sistemi
çekirdeği bütün donanımmış gibi davranır.
Bir sanal makine sade donanıma benzeyen bir arayüz
sağlar.
İşletim sistemi çoklu işlemlerin, kendi (sanal) belleğiyle
kendi işlemcisi üzerinde çalışan bir yanılsamasını
oluşturur.
7
Silberschatz, Galvin and Gagne 2002 3.37
Sanal Makineler (Devamı)
Somut makinelerin kaynakları, sanal makineler yaratmak
için dosya paylaşımı gerçekleştirir.
CPU planlaması, kendilerine ait işlemcileri olan kullanıcılar
için bir görünüm yaratabilir.
Sargı ve dosya sistemi sanal kart okuyucularını ve sanal
kablolu yazıcılarını destekleyebilir.
Kullanıcı zaman paylaşımlı bir terminal, sanal makine
konsol operatoru gibi hizmet verebilir.
Operating System Concepts Silberschatz, Galvin and Gagne 2002 3.38 Operating System Concepts
Sistem Modelleri
Sanal Olmayan Makine Sanal Makine
Silberschatz, Galvin and Gagne 2002 3.39 Operating System Concepts
Sanal Makinelerin Avantaj ve Dezavantajları
Sanal makinenin konsepti , her sanal makine
diğerlerinden soyutlandığı andan itibaren sistem
kaynaklarının tam anlamıyla korunmasına olanak
sağlar.Bu soyutlama kaynaklara direk erişime izin
vermez.
Sanal makine ağı, işletim sistemlerinin araştırılması ve
geliştirilmesinde mükemmel bir araç niteliğindedir.
Sanal makinelerde sistem gelişimi somut makinelere
nazaran oluşturulmuştur ki bu da sistem işletiminin
aksamasını engeller niteliktedir.
Sanal makine konseptinin efor gerektiren kopyasını
desteklemesi yönünden esas makineye göre
yaptırımını gerçekleştirmesi zordur.
Silberschatz, Galvin and Gagne 2002 3.40 Operating System Concepts
Sistem Tasarım Hedefleri
Kullanıcı hedefleri – işletim sistemi kullanımı kolay
öğrenilebilirliği, güvenilirliği ve hızlı oluşu yönünden
uygun olmalıdır.
Sistem hedefleri– işletim sistemi, esnekliği,hatasız
oluşu ve verimliliği gibi yapılandırılması, korunması
yöndünden dizaynı basit olmalıdır.
Silberschatz, Galvin and Gagne 2002 3.41 Operating System Concepts
İşeyişi ve Politikaları
İşleyiş birşeyleri nasıl yapmayı saptar, politika ne
olacağına karar verir.
Politikanın, işleyişten ayrımı çok önemli bir
unsurdur, bu ayrım eğer politika sonradan
değişme ye müsait ise maksimum esnekliğe imkan
sağlar.
Silberschatz, Galvin and Gagne 2002 3.42 Operating System Concepts
Sistem Uygulamaları
Assembly dilinde yazılanlara dayanarak, şuan işletim
sistemi daha yüksek dil seviyeleriyle yazılabilmektedir.
Yüksek seviyeli bir dille yazılmış kod:
daha hızlı yazılabilir.
daha kısa ve etkilidir.
debug edilmesi ve anlaşılabilirliği daha kolay hale gelir.
Eğer bir işletim sistemi yüksek seviyeli bir dille yazılmış
ise diğer donanımlara tanışması çok daha kolay hale
gelir.
8
Silberschatz, Galvin and Gagne 2002 3.43 Operating System Concepts
Sistem Jenerasyonu(SYSGEN)
İşletim sistemleri herhangi bir bilgisayarda çalışacak
şekilde tasarlandı; sistem her türlü bilgisayara
konfigure edilir halde olmalıdır.
Sistem Jenerasyon programı donanım sistemlerinin
konfigrasyonuna ilişkin bilgileri desteklemelidir.
Önyükleme– kernelin yüklenmesiyle bilgisayarın
başlaması olayıdır.
Bootstrap program – ROM’da depolanan kod kerneli
yerleştirebilir , hafızaya yükleyebilmelidir ve
uygulamasını çalıştırabilir olmalıdır.
Silberschatz, Galvin and Gagne 2002 3.44
Sistem Çağrı Arayüzü
Güvenilir bir işletim sisteminde donanım kaynaklarının
doğru bir biçimde paylaştırılması ve birbirinden
yalıtılması gerekmektedir.
Bunları yapabilmek için bir işletim sisteminin
soyutlamaları, sistem çağrı arayüzü (system call
interface) olarak da bilinen işletim sisteminin arayüzü
kullanır.
Silberschatz, Galvin and Gagne 2002 3.45
API (Application Programming
Interface)
Tüm sistem yazılımları bir uygulama programlama
arayüzü – API (Application Programming Interface)
yoluyla ulaşılabilinir.
API; bir yazılım veya sistem yazılım parçasının
programlama arayüzüdür. Veritabanları, VBasic
editörü gibi.
Programcılar uygulama programlama arayüzlerini
kullanırlarken, işletim sistemi, sistem çağrı
arayüzünü kullanır.
Silberschatz, Galvin and Gagne 2002 3.46
API (Application Programming
Interface)
Uygulama programlama arayüzleri sistem
yazılım arayüzlerine ulaşarak bunların
kullanıcı tarafından kullanılabilmesini sağlar.
Microsoft Windows sistem çağrı arayüzünü
“Win32 API” olarak adlandırmıştır.
Silberschatz, Galvin and Gagne 2002 3.47
Standart API aracılığıyla Sistemi Çağrı örneği
Bir dosyadan okuma yapmak için bir işlev - Win32 API ReadFile () fonksiyonu düşünün
ReadFile geçirilen parametreleri () vardır.
Handle file- dosyanın okunmasını
LPVOID buffer - veri içine okumak ve yazılı olacak bir tampon
DWORD BytesToRead – tampon içine okunacakbayt sayısı(tampon boyutu)
LPDWORD bytesRead - son okuma sırasında okunan bayt sayısı
LpOverlapped OVL - I / O kullanılan çakışan-engellenmeyen olup
olmadığını gösteren
Silberschatz, Galvin and Gagne 2002 3.48
API – Sistem Çağrı Uygulaması
OS tarafından sağlanan hizmetlere arayüzü iki bölümden oluşur: YüksekSeviye dil arayüzü - bir sistem kütüphanesine bir parçası
Kullanıcı modunda çalıştırır Uygulanan standart bir prosedür aramayı kabul etmek için
2inci kısımda tuzakları(traps) Çekirdek parçası
Sistem kipinde çalıştırır Gerekli sistem hizmeti uygular
arayanı engelleme neden olabilir(Beklemek zorunda) Tamamlama (çağrı başarı veya başarısızlık rapor edebilir) ilk
kısma geri döner sonra
9
Silberschatz, Galvin and Gagne 2002 3.49
Sistem Çağrı Arabirimi Nasıl Çalışır??
11 steps to execute the service
fread (fd, buffer, nbytes)
Return to caller
Trap to kernel
Code of "read" into register
Increment SP 11
Call "fread"
Push fd
Push &buffer
Push nbytes
User space
Kernel space(Operating
system)
Library procedure "fread"
Application calling "fread"
DispatcherSys call
handler
4
5
7 8
9
10
1
2
3
• Uygulama programı bir sistem çağrı yapar:
Bir sistem kitaplığı rutin ilk denir Bu çekirdek sistemi standart (yerli
API) için çağrı dönüşümleri ve tuzaklar
• Kontrol sistemi modunda
çalışırken çekirdek tarafından alınır
• Hizmet "kodu" göre, Çağrı
memuru Kernel kısmen sorumlu çağırır
• Istenen hizmetin niteliğine bağlı
olarak, çekirdek çağıran süreç engelleyebilir
• Çağrı bittikten sonra, çağıran süreç yürütme sıradan bir işlevi çağrılmış gibi sonucu (başarılı /
başarısız) elde sürdürür Silberschatz, Galvin and Gagne 2002 3.50
Standard C Library Example C programı (yazma çağırır) kütüphane çağrısının, () printf sistem
çağrısı çağırmak
Silberschatz, Galvin and Gagne 2002 3.51
System API Standards
Üç en sık API standartları POSIX tabanlı sistemler için POSIX API, Windows için Win32 API, Java sanal makinesi için Java API (JVM)
POSIX (IEEE 1003.1, ISO / IEC 9945) Esas Çok yaygın olarak kullanılan standart (dahil) C-dili hem tanımlar sistem çağrıları ve onların işlevsellik ve komut satırı biçimi ile birlikte zorunlu sistem programları Örneğin ls-w dir Bir 'geniş' biçiminde bir dizindeki dosyaların listesini yazdırır Komple şartname http://www.opengroup.org/onlinepubs/9699919799/nframe.html altındadır
Win32 (Micro $ oft Windows tabanlı sistemlerde) Sistem çok karmaşık birçok Windows GUI rutinleri, gerçekten tam özellikleri ile birlikte aramaları belirtir
Silberschatz, Galvin and Gagne 2002 3.52
Types of System Calls
Hizmet kümesi (görünüşte bağımsız) gruplar:
Proses kontrol ve IPC (Inter-Process Communication)
Bellek yönetimi (istek üzerine bellek alanı tahsis
edilmesi ve boşaltma)
Dosyalarda veri erişim (Dosya ve dosya sistem
yönetimi)
Cihaz yönetimi
İletişim
Ağ ve dağıtık hesaplama desteği
Diğer hizmetler
örneğin, profilleme
ayıklama
vb
Silberschatz, Galvin and Gagne 2002 3.53
Process Control Calls (1)
fork() – create a new process pid = fork();
The fork() function shall create a new process. The new process (child process) shall be an exact copy of the calling process (parent process) except some process’ system properties
It returns ‘twice’ return value == 0 ... child
return value > 0 ... parent (returned value is the child’s pid)
exit() – terminate a process
void exit(int status); The exit() function shall then flush all open files with unwritten buffered data and close all open files. Finally, the process shall be terminated and system resources owned by the process shall be
freed The value of ‘status’ shall be available to a waiting parent process
The exit() function should never return
Silberschatz, Galvin and Gagne 2002 3.54
Process Control Calls (2)
wait, waitpid – wait for a child process to stop or terminate pid = wait(int *stat_loc);
pid = waitpid(pid_t pid, int *stat_loc, int options);
The wait() and waitpid() functions shall suspend the calling process and obtain status information pertaining to one of the caller's child processes. Various options permit status information to be obtained for child processes that have terminated or stopped.
execl, execle, execlp, execv, execve, execvp – execute a file int execl(const char *path, const char *arg0, ...);
The members of the exec family of functions differ in the form and meaning of the arguments
The exec family of functions shall replace the current process image with a new process image. The new image shall be constructed from a regular, executable file called the new process image file.
There shall be no return from a successful exec, because the calling process image is overlaid by the new process image; any return indicates a failure
10
Silberschatz, Galvin and Gagne 2002 3.55
Memory Management Calls
System calls of this type are rather obsolete Modern virtual memory mechanisms can allocate memory
automatically as needed by applications Important system API calls are:
malloc() – a memory allocator void *malloc(size_t size);
The malloc() function shall allocate unused space for an object whose size in bytes is specified by size and whose value is
unspecified. It returns a pointer to the allocated memory space
free() – free a previously allocated memory void free(void *ptr);
The free() function shall cause the space pointed to by ptr to be deallocated; that is, made available for further allocation.
If the argument does not match a pointer earlier returned by a malloc() call, or if the space has been deallocated by a call to
free(), the behavior is undefined.
Silberschatz, Galvin and Gagne 2002 3.56
File Access Calls (1)
POSIX-based operating systems treat a file in a very general sense
File is an object that can be written to, or read from, or both. A file has certain attributes, including access permissions and type.
File types include regular file,
character special file ... a ‘byte oriented device’, block special file ... a ‘block oriented device’,
FIFO special file, symbolic link, socket, and directory.
To access any file, it must be first opened using an open() call that returns a file descriptor (fd).
fd is a non-negative integer used for further reference to that particular file
In fact, fd is an index into a process-owned table of file descriptors
Any open() (or other calls returning fd) will always assign the LOWEST unused entry
in the table of file descriptors
NULL
NULL
5
4
3
0 STDIN
1 STDOUT
2 STDERR
Silberschatz, Galvin and Gagne 2002 3.57
File Access Calls (2)
open – open file fd = open(const char *path, int oflag, ...);
The open() function shall establish the connection between a file and a file descriptor. The file descriptor is used by other I/O functions to refer to that file. The path argument points to a
pathname naming the file.
The parameter oflag specifies the open mode: ReadOnly, WriteOnly, ReadWrite Create, Append, Exclusive, ...
close – close a file descriptor err = close(int fd);
The close() function shall deallocate the file descriptor indicated by fd. To deallocate means to make the file descriptor available for
return by subsequent calls to open() or other functions that allocate file descriptors.
When all file descriptors associated with an open file description have been closed, the open file description shall be freed.
Silberschatz, Galvin and Gagne 2002 3.58
File Access Calls (3)
read – read from a file
b_read = read(int fd, void *buf, int nbyte);
The read() function shall attempt to read nbyte bytes from the file
associated with the open file descriptor, fd, into the buffer pointed
to by buf.
The return value shall be a non-negative integer indicating the
number of bytes actually read.
write – write to a file
b_written = write(int fd, void *buf, int nbyte);
The write() function shall attempt to write nbyte bytes from the
buffer pointed to by buf to the file associated with the open file
descriptor fd.
The return value shall be a non-negative integer indicating the
number of bytes actually written.
Silberschatz, Galvin and Gagne 2002 3.59
File Access Calls (4)
lseek – move the read/write file offset where = lseek(int fd, off_t offset, int whence);
The lseek() function shall set the file offset for the open associated with the file descriptor fd, as follows:
If whence is SEEK_SET, the file offset shall be set to offset bytes.
If whence is SEEK_CUR, the file offset shall be set to its current location
plus offset.
If whence is SEEK_END, the file offset shall be set to the size of the file
plus offset.
The lseek() function shall allow the file offset to be set beyond the end of the existing data in the file creating a gap. Subsequent
reads of data in the gap shall return bytes with the value 0 until some data is actually written into the gap (implements sparse file).
Upon successful completion, the resulting offset, as measured in bytes from the beginning of the file, shall be returned.
An interesting use is: where = lseek(int fd, 0, SEEK_CUR);
will deliver the “current position” in the file.
Silberschatz, Galvin and Gagne 2002 3.60
File Access Calls (5)
dup – duplicate an open file descriptor
fd_new = dup(int fd);
The dup() function shall duplicate the descriptor to the open fileassociated with the file descriptor fd.
As for open(), the LOWEST unused file descriptor should be
returned.
Upon successful completion a non-negative integer, namely the file descriptor, shall be returned; otherwise, -1 shall be returned to
indicate the error.
stat – get file status err = stat(const char path, struct stat *buf);
The stat() function shall obtain information about the named file and write it to the area pointed to by the buf argument. The path
argument points to a pathname naming a file. The file need not be
open.
The stat structure contains a number of important items like:
device where the file is, file size, ownership, access rights, file time
stapms, etc.
11
Silberschatz, Galvin and Gagne 2002 3.61
File Access Calls (6)
chmod – change mode of a file
err = chmod(const char *path, mode_t mode);
The chmod() function shall the file permission of the file named by the path argument to the in the mode argument. The application
shall ensure that the effective privileges in order to do this.
pipe – create an interprocess communication channel err = pipe(int fd[2]);
The pipe() function shall create a pipe and place two file descriptors, one each into the arguments fd[0] and fd[1], that
refer to the open file descriptors for the read and write ends of the
pipe. Their integer values shall be the two lowest available at the
time of the pipe() call.
A read on the file descriptor fd[0] shall access data written to the
file descriptor fd[1] on a first-in-first-out basis.
The details and utilization of this call will be explained later.
Silberschatz, Galvin and Gagne 2002 3.62
File & Directory Management Calls (1)
mkdir – make a directory relative to directory file descriptor
err = mkdir(const char *path, mode_t mode);
The mkdir() function shall create a new directory with name path.
The new directory access rights shall be initialized from mode.
rmdir – remove a directory err = rmdir(const char *path);
The rmdir() function shall remove a directory whose name is given by path. The directory shall be removed only if it is an empty
directory.
chdir – change working directory err = chdir(const char *path);
The chdir() function shall cause the directory named by the pathname pointed to by the path argument to become the current
working directory. Working directory is the starting point for path
searches for relative pathnames.
Silberschatz, Galvin and Gagne 2002 3.63
File & Directory Management Calls (2)
link – link one file to another file
err = int link(const char *path1, const char *path2);
The link() function shall create a new link (directory entry) for the existing file identified by path1.
unlink – remove a directory entry err = unlink(const char *path);
The unlink() function shall remove a link to a file.
When the file's link count becomes 0 and no process has the file open, the space occupied by the file shall be freed and the file shall
no longer be accessible. If one or more processes have the file open when the last link is removed, the link shall be removed
before unlink() returns, but the removal of the file contents shall be postponed until all references to the file are closed.
chdir – change working directory err = chdir(const char *path);
The chdir() function shall cause the directory named by the pathname pointed to by the path argument to become the current working directory. Working directory is the starting point for path
searches for relative pathnames.
Silberschatz, Galvin and Gagne 2002 3.64
Device Management Calls
System calls to manage devices are hidden into ‘file calls’ POSIX-based operating systems do not make difference between
traditional files and ‘devices’. Devices are treated as ‘special files’
Access to ‘devices’ is mediated by opening the ‘special file’ and accessing it through the device.
Special files are usually ‘referenced’ from the /dev directory.
ioctl – control a device int ioctl(int fd, int request, ... /* arg */);
The ioctl() function shall perform a variety of control functions on devices. The request argument and an optional third argument
(with varying type) shall be passed to and interpreted by the appropriate part of the associated with fd.
Silberschatz, Galvin and Gagne 2002 3.65
Other Calls
kill – send a signal to a process or a group of processes err = kill(pid_t pid, int sig);
The kill() function shall send a signal to a process specified by pid. The signal to be sent is specified by sig.
kill() is an elementary inter-process communication means
The caller has to has to have sufficient privileges to send the signal to the target.
signal – a signal management void (*signal(int sig, void (*func)(int)))(int);
The signal() function chooses one of three ways in which receipt of the signal sig is to be subsequently handled.
If the value of func is SIG_DFL, default handling for that signal shall occur.
If the value of func is SIG_IGN, the signal shall be ignored. Otherwise, the application shall ensure that func points to a function to
be called when that signal occurs. An invocation of such a function is called a "signal handler".
Silberschatz, Galvin and Gagne 2002 3.66
POSIX Win32 Description
fork CreateProcess Create a new process
wait WaitForSingleObject The parent process may wait for the child to finish
execve -- CreateProcess = fork + execve
exit ExitProcess Terminate process
open CreateFile Create a new file or open an existing file
close CloseHandle Close a file
read ReadFile Read data from an open file
write WriteFile Write data into an open file
lseek SetFilePointer Move read/write offset in a file (file pointer)
stat GetFileAttributesExt Get information on a file
mkdir CreateDirectory Create a file directory
rmdir RemoveDirectory Remove a file directory
link -- Win32 does not support “links” in the file system
unlink DeleteFile Delete an existing file
chdir SetCurrentDirectory Change working directory
POSIX and Win32 Calls Comparison
Only several important calls are shown
12
Silberschatz, Galvin and Gagne 2002 3.67
Kaynakçalar
Operating System Concepts
Silberschatz, Galvin, 2002
Öğr.Gör. Dr. Dr. Şirin KARADENİZ