introduction operating systems (234123) – spring 2013 introduction dan tsafrir (11/3/2013) os...

40
Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro 1

Upload: rachel-waters

Post on 27-Dec-2015

223 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 1

Operating Systems (234123) – Spring 2013Introduction

Dan Tsafrir (11/3/2013)

Page 2: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 2

Admin – staff• Lecturer in charge

– Prof. Dan Tsafrir

• Lecturer– Dr. Leonid Raskin

• TA in charge– Mr. Omri Azencot

• TAs– Ms. Anastasia Braginsky– Mr. Raja Giryes– Mr. Ilya Lesokhin– Mr. Alex Kreimer

• Homework checker– Mr. Hassan Abassie

Page 3: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 3

Admin – course material & grading• Course website

– http://webcourse.cs.technion.ac.il/234123– Contains all course materials, e.g., office hours times & locations

• Lecture material– Updated on the fly, possibly significantly – Updates will be published as soon as possible

• Grades– Exam: 65% - 75%

• Must be >= 55 to pass– HW: 30% - 35%

• 4 wet, 4 dry, uneven weights, takef• Not allowed to transfer grades from previous semester

Page 4: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 4

Admin – books• “Operating System Concepts”

– By A. Silberschatz, P.B. Galvin, and G. Gagne– 9th edition (>= 6 is fine)

• “Understanding the Linux Kernel”– By Daniel P. Bovet & Marco Cesati– 3rd edition

• “Notes on Operating Systems”– By Dror G. Feitelson– Available for download via course website– This lecture: Chapters 1, Appendix A, and some of Chapter 2

• A few others are listed in website, to those interested

Page 5: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 5

LET US BEGINHaving gone over the admin stuff

Page 6: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 6

What’s an operating system?• A piece of software (SW) acting as an intermediary between

user applications (apps) and the computer hardware (HW)

• First piece of SW to run on a computer when it’s booted

• Its job– Coordinate the execution of all SW,

mainly user apps– Provide various common services

needed by users and apps

• Common to draw it like so– But this is an oversimplification…

user

application

OS

HW

Page 7: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 7

What’s an OS?

signals

It’s morecomplex…

Page 8: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 8

physical HW

What’s an OS?

It’s even more complex…

Windows 8 “guest”virtual machine (VM)

Windows XP“guest” VM

Linux“guest” VM

app

“host” OS (called “hypervisor”)virtual HW

• The hypervisor (which is also an “OS”) can be: Linux / KVM, Vmware Workstation / Windows, Mac OS X / Parallels, …

• Topic is called “virtualization”

Page 9: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 9

For simplicity• Unless stated otherwise, we will focus on “classic” OS setup

1. Non-virtualized OS (also called “bare metal” OS)2. System with one CPU (CPU = processor core)

• Both assumptions– Becoming less and less relevant in today’s world– But we’ll manage

• So, under the above assumptions…

Page 10: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 10

A possible sequence of system actions1. The OS executes; schedules some application app#1 (=makes it run)2. App#1 runs = CPU executes its (non-privileged) ops; OS remains uninvolved 3. HW clock interrupt fires, invoking OS’s “interrupt handler” routine4. Interrupt handler updates OS’s notion of time +

invokes OS scheduler if app#1 has been running too long (it is said that app#1 exhausted it “quantum”)

5. Scheduler chooses app#2 to run in place of app#1 => “context switch”6. App#2 runs (non-privileged ops => without OS involvement);

after a while, app#2 performs a “system call” to , e.g., read from a file7. The system call causes a “trap” into the OS; the OS initiates the I/O op

(using some privileged ops); it then puts app#2 to sleep, to await the I/O completion, and it chooses app#3 to run in its place

8. App#3 runs…Note: • Either OS or app are running, not both• OS regains control when (1) HW interrupt fires or (2) sys call is invoked

Page 11: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 11

The OS is reactive• “Ordinary” programs

– Get some input, do some processing, produce output, and terminate – Have a main function, – Which is (more or less) the one and only entry point for the program

• In contrast, the OS– Waits (and reacts) to events– No main, but rather multiple points of entry, one per event type– Doesn’t terminate; when one event is finished, wait for the next– Goal: handle events as quickly as possible and allow apps to run– Q: why doesn’t the OS get stack?

• Events can be classified into two– HW device interrupts (keyboard, clock, hard drive, network card, ...)– Systems calls (apps explicitly request service)

Page 12: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 12

The OS performs “resource management”• Example

– Multiprogramming is one of the main features of OSes– Allows multiple apps to execute “at the same time” on a single CPU– To implement such concurrent execution, OS juggles the system’s

resources between the competing apps– Trying to make it look as if each one has the computer for itself– At the heart of multiprogramming lies “resource management”:

• Deciding which running app will get which resources

• Resources to manage– Obvious ones (taking the view of an app):

• CPU, memory, disk, NIC, keyboard, mouse, screen display– But also resources internal to the OS, e.g.:

• Disk space for “paging” (provide illusion of a huge memory)• System tables (running apps, open files, network channels, etc.)

Page 13: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 13

The OS provides “services”• The OS provides services to running apps, e.g.,

– The ability to store data in files– The ability to communicate with remote machines– The ability to communicate with another app via shared memory– The ability to draw on screen– …

• Each service involves two aspects1. Abstraction – provides convenience & portability by:

(i) offering more meaningful, higher-level interfaces, and by (ii) hiding HW details , e.g.,• Apps use “files” instead of handing numerous raw block devices

2. Isolation – allow many apps to co-exist using the same HW devices without falling over each other’s feet, e.g.,• Several apps send/receive data over a network; OS keeps the data

streams separated from each other

Page 14: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 14

OS service: “abstract machines”• Abstract machines simplify

– The dynamics of multiprogramming are complex– Each app runs for a while, then preempted, then runs again, and so on– OS presents an abstraction that hides the complexity– Each app sees an abstract machine (seemingly) dedicated to itself– Apps are unaware of the OS activity

• Abstract machines isolate– Multiprogramming means there are many abstract machines, not one

• Each app gets its own abstract machine– Abstract machines are isolated from each other

• The abstraction hides all resources used to support other apps• Thus, each apps sees the system as if it were dedicated to itself,

and the OS juggles resources to support this illusion– Notably, the computation is still correct despite the multiprogramming

Page 15: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 15

• Abstraction allows for decoupling from physical restrictions– Abstract machine presented by OS is “better” than physical HW – By virtue of supporting more convenient abstractions

• Apps don’t accessphysical resourcesdirectly– There’s a level of

indirection– Otherwise how

would we support,say, a 4GB of (virtual) memorywith only, say, 1GB of (physical) memory?

Pros of abstraction – a “better” machine

abstract

Page 16: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 16

Pros of abstraction – portability• Portability

– The ability to correctly run the same exact program in different environments (in terms of source code, not binary)

• Portability across different HW– PowerPC (IBM), x86 (Intel, AMD), and SPARC (Oracle) chips support

virtual memory completely differently– Namely, the aforementioned indirection is completely different– Linux runs on both type of chips, handling the HW diff– No need to rewrite user apps so as to cope with HW diff

• Portability across different OSes– There are lots of UNIX variants (Linux, HPUX, Solaris, *BSD, AIX,…)– All (more or less) implement the POSIX interface

• POSIX = “Portable Operating System Interface”– An app that obeys POSIX will run across all of these OSes unchanged

Page 17: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 17

Three different ways to view an OS1. By its programming interface

– Its system calls

2. According to the services it provides– Time slicing (how multiprogramming is implemented as explained

earlier), a file system, etc.

3. According to its internals, algorithms, and data structures

• An OS is defined by its interface– Different implementation of the same interface are equivalent as far

as users and apps are concerned

• But the lectures are organized according to services– For each one we’ll detail the internal structures & algorithms used– Occasionally, we’ll provide examples of interfaces, mainly from Unix

Page 18: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 18

Interaction between subsystems• OS components can be studied in isolation; we’ll focus on

– Process handling• Processes are the agents of processing; the OS creates them,

schedules them, and coordinates their interactions– Memory management

• Memory is allocated to processes as needed, but there might not be enough for all, so paging is used

– File system• Files are an abstraction providing named data repositories based

on disks that store individual blocks; the OS does the bookkeeping

Page 19: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 19

Interaction between subsystems• But OS components typically interact, e.g.,

– OS improves utilization by overlapping computation of one process with the read ops of another

– Likewise, if a process requires a memory page that currently resides on disk (due to paging), it suffers a page fault, which results in an I/O op; another process is run in the meanwhile.

– Memory availability may determine if a new process is started or made to wait

• We’ll initially ignore such interactions to keep things simple

Page 20: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 20

Scope – focusing on the kernel• All the things we mentioned so far relate to the operating

system “kernel”– Which will indeed be our focus

• But when one talks of an OS, one is typically referring to a “distribution”, which contains the following elements:– The Unix kernel itself; strictly speaking, this is “the OS”– The libc library; provides runtime environment for programs written in

C (e.g., contains the implementation of printf, strcpy, etc.)– Various tools, such as gcc, the GNU C compiler– Many useful utilities/programs you may need, e.g., windowing system,

desktop, and shell

• We’ll focus exclusively on the kernel — what it is supposed to do, and how it does it

Page 21: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 21

HW SUPPORT FOR THE OS

Page 22: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 22

Some HW mechanisms to support the OS• HW clock• Atomic synchronization operations• Interrupts• System calls• Memory virtualization & protection• I/O controllers

– DMA (direct memory access)– Memory-mapped I/O– IOMMU (I/O memory management unit)

• Protected mode• Privileged operations (instructions)

Page 23: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 23

Privileged operations & privileged mode• Some sensitive operations can only be invoked by the OS

– All operations related to I/O– All operations related to memory indirection layers – Blocking/unblocking interrupts (why would we want to do that)– Memory usage bits– …

• HW supports at least 2 privilege modes– Kernel mode (ring 0 on x86)

• Kernel runs in this mode– User mode (ring 3 on x86)

• User apps run in this mode– Mode is saved in a “status bit” in a special register

• Which is accessible in kernel mode only– Privileged operations work only in kernel mode

Page 24: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 24

Reading from disk on Linux/x86• User app invokes ‘read’ system call

– read(int fileDescriptor, char *buffer, size_t bufferSize)

• libc does the following (in user mode)– Assigns the number ID associated with ‘read’ into register ‘eax’– Prepares the other parameters (according to some convention)– Executes: int 0x80 (called “trap”)

• A synchronous interrupt (“int”) initiated by SW• (0x80 in hexadecimal = 128 in decimal)

• Control transfers to kernel– HW changes mode from unprivileged (ring 3) to privileged (ring 0)– HW accesses IDT (interrupt descriptor table) array in entry 128– IDT contains pointer-to-functions (addresses to kernel code)– Content of IDT is set by OS at boot time; user code can’t access it– Entry 128 of IDT points to the kernel’s “system call handler” routine– HW invokes this handler

Page 25: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 25

Reading from disk on Linux/x86• Within the kernel

– The system call identifier (‘read’) is used in a big switch statement to find and call the appropriate OS function that actually perform the desired service (‘sys_read’).

– The latter function then starts by retrieving/validating its arguments from where they were stored by the wrapper libc function

– It then generates an I/O read request that will be processed by the disk using DMA (no need to further involve the CPU)

– OS then suspends the user app until the I/O read is completed– OS resumes another ready-to-run app

• I/O read is completed (a few milliseconds later)– An interrupt is generated, invoking the matching handler from IDT– OS figures out that the app’s I/O is completed,– OS changes app’s status from ‘waiting’ to ‘ready to run’– When app is scheduled next, it will resume from after “int 0x80”

Page 26: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

OS (234123) - spring 2013 - intro 26

PROCESSES

Page 27: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

(2009מערכות הפעלה )אביב © חגית עטיה 27

תהליכים?מהו תהליך .מבני הנתונים לניהול תהליכים .החלפת הקשר .ניהול תהליכים ע"י מערכת ההפעלה

Page 28: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

(2009מערכות הפעלה )אביב © חגית עטיה 28

תהליך :אבסטרקציה

יחידת הביצוע לארגון פעילות המחשביחידת הזימון לביצוע במעבד ע"י מערכת ההפעלה)תוכנית בביצוע )סדרתי = פקודה-אחת-אחר-השנייה

job, task, sequential processנקרא גם

Page 29: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

(2009מערכות הפעלה )אביב © חגית עטיה 29

מה מאפיין תהליך? תהליך לעומת תוכנית:

תוכנית היא חלק ממצב התהליך)אפשר לייצר כמה תהליכים מאותה תוכנית )שירוצו במקביל

מרחב כתובותקוד התוכניתנתוניםמחסנית זמן-ביצועprogram counterרגיסטרים( מספר תהליךprocess id)

Page 30: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

(2009מערכות הפעלה )אביב © חגית עטיה 30

מרחב הכתובות של התהליך

0x00000000

0xFFFFFFFF

address space

code)text segment(

static data)data segment(

heap)dynamic allocated mem(

stack)dynamic allocated mem(

ProgramCounter

StackPointer

Page 31: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

(2009מערכות הפעלה )אביב © חגית עטיה 31

מצבי התהליך:כל תהליך נמצא באחד המצבים הבאים

( מוכןready)( רץrunning)( מחכהwaiting )

?מתי מזמנים / מפנים תהליכים

New

Terminated

Ready

Running

Waiting

create

kill/finish I/O, page fault, etc.

I/Odone

resumepreempt

טווח קצר

/טווח בינוניארוך

Page 32: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

(2009מערכות הפעלה )אביב © חגית עטיה 32

מבני הנתונים של תהליךבכל נק' זמן יש הרבה שדות!O(100), מכיל Linuxב

תהליכים פעילים במערכת מצבלכל תהליךProcess control block

(PCB) שומר את מצב התהליך כאשר אינו רץ.

נקראProcess Descriptor Linuxב-

נשמר כאשר התהליךמפונה, נטען כאשר התהליך

מתחיל לרוץ.

Process id (PID)

Execution state

Program counter

Stack pointer

Registers

Username

Scheduling priority

Memory limits

Page 33: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

(2009מערכות הפעלה )אביב © חגית עטיה 33

PCBמצב המעבד וה-:כאשר תהליך רץ, המצב שלו נמצא במעבד

PC, SPרגיסטרים ,רגיסטרים לקביעת גבולות זיכרון

כאשר המעבד מפסיק להריץ תהליך )מעבירו למצב.PCBהמתנה(, ערכי הרגיסטרים נשמרים ב-

כאשר המעבד מחזיר תהליך למצב ריצה, ערכי.PCBהרגיסטרים נטענים מה-

Context Switch העברת המעבד מתהליך אחד :לשני.

Page 34: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

(2009מערכות הפעלה )אביב © חגית עטיה 34

Context switch1תהליך מערכת ההפעלה2תהליך

מתבצע

מתבצע

מוכן )אולי אחרי תק'המתנה(

מוכן

מוכן

מתבצע

save state in PCB1

load state from PCB2

save state in PCB2

פסיקה או המתנה

פסיקה או המתנה

load state from PCB1

Page 35: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

(2009מערכות הפעלה )אביב © חגית עטיה 35

תורי מצביםמערכת ההפעלה מחזיקה תורים של תהליכים

)תור )או מבנה נתונים מתוחכם יותרready

תורwaiting-למשל ל , deviceמסוים Wait queue header

cat pcb firefox pcbhead pointertail pointer

Ready queue header

head pointer

tail pointer

firefox pcb emacs pcb ls pcb

Page 36: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

(2009מערכות הפעלה )אביב © חגית עטיה 36

ותורי המצביםPCBה- הוא מבנה נתונים בזיכרון מערכת ההפעלה.PCBה-

כאשר התהליך נוצר, מּוקצה עבורוPCB עם ערכי( התחלה(, ומשורשר לתור המתאים )בדרך-כלל,

ready.)-הPCB.נמצא בתור המתאים למצבו של התהליך -כאשר מצב התהליך משתנה, הPCB שלו מועבר

מתור לתור.

-כאשר התהליך מסתיים, הPCB.שלו משוחרר

Page 37: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

(2009מערכות הפעלה )אביב © חגית עטיה 37

יצירת תהליך)יכול ליצור תהליך אחר )הבן(תהליך אחד )האב

שדהppid בביצוע ps -al-ב Linux.

.בדרך-כלל, האב מגדיר או מוריש משאבים ותכונות לבניו-בLinux הבן יורש את שדה ,user.ועוד ,

.האב יכול להמתין לבנו, לסיים, או להמשיך לרוץ במקביל רק תהליך אב יכול להמתין לבניו

CreateProcess(…,prog.exe,…) יש קריאת Windowsב מייצרת תהליך חדש )ללא קשרי אבות/בנים( אשר מתחיל לבצע את

prog.

Page 38: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

(2009מערכות הפעלה )אביב © חגית עטיה 38

() UNIX:forkיצירת תהליכים ב-int main(int argc,

char **argv){ int child_pid = fork(); if (child_pid == 0) { printf(“Son of %d is %d\n”, getppid(),getpid()); return 0; } else { printf(“Father of %d is

%d\n”, child_pid,getpid());

return 0; } }

יוצר ומאתחלPCB. מיצר מרחב כתובות חדש, ומאתחל

אותו עם העתק מלא של מרחב הכתובות של האב.

מאתחל משאבי גרעין לפי משאביהאב )למשל, קבצים פתוחים(

באג נפוץ הוא שכיחת סגירת קבציםפתוחים של האב אצל הבן

-שם את הPCBבתור המוכנים עכשיו יש שני תהליכים, אשר נמצאים

באותה נקודה בביצוע אותה תוכנית. שני התהליכים חוזרים מהfork:

0הבן, עם ערך( האב, עם מספר התהליךpid של )

הבן

)( forkנראה בהמשך מימוש יעיל יותר ל

Page 39: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

(2009מערכות הפעלה )אביב © חגית עטיה 39

איך מפעילים תוכנית חדשה?int execv(char *prog, char **argv)

.עוצר את ביצוע התוכנית הנוכחית טוען אתprog.לתוך מרחב הכתובות מאתחל את מצב המעבד, וארגומנטים עבור התוכנית

החדשה.-ה( מפנה את המעבדPCB.)מועבר לתור המוכנים

יוצר תהליך חדש!לא

Page 40: Introduction Operating Systems (234123) – Spring 2013 Introduction Dan Tsafrir (11/3/2013) OS (234123) - spring 2013 - intro1

(2009מערכות הפעלה )אביב © חגית עטיה 40

UNIX shellדוגמא: int main(int argc, char **argv){ while (1) { char *cmd = get_next_command(); int child_pid = fork(); if (child_pid == 0) {

execv(cmd); fprintf(stderr, “exec failed!”); } else { wait(child_pid); } }}