Presentation is loading. Please wait.

Presentation is loading. Please wait.

Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Bab 3: Proses.

Similar presentations


Presentation on theme: "Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Bab 3: Proses."— Presentation transcript:

1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Bab 3: Proses

2 3.2 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Bab 3: Proses n Konsep Proses n Penjadwalan Proses n Operasi Proses n InterProcess Communication n Contoh Sistem IPC n Komunikasi Sistem Client-Server

3 3.3 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Tujuan n Memperkenalkan proses -- sebuah program dieksekusi yang merupakan dasar dari semua komputasi n Menggambarkan berbagai fitur proses, termasuk penjadwalan, pembuatan, pengakhiran, dan komunikasi dari proses n Mengeksplorasi IPC menggunakan shared memory dan message passing n Menggambarkan komunikasi pada sistem client-server

4 3.4 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Konsep Proses

5 3.5 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Question n Apa yang dimaksud dengan process? n Apakah ini proses? l Microsoft Word l Adobe Photoshop l Notepad

6 3.6 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Konsep Proses n Sebuah OS mengeksekusi berbagai program: l Batch system – jobs l Time-shared systems – user programs atau tasks n Istilah job dan process akan digunakan secara bergantian dalam buku ini n Proses – sebuah program yang dieksekusi, proses eksekusi harus berkembang secara berurutan n Program adalah entitas yang bersifat pasif yang disimpan pada disk (executable file), sedangkan proses bersifat aktif l Program menjadi proses ketika file executable dimuat ke dalam memori n Eksekusi program dimulai via klik mouse pada GUI atau via command line n Satu program dapat beberapa proses l Pertimbangkan beberapa user menjalankan program yang sama

7 3.7 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Bagian Proses n Kode program, atau bisa disebut text section n Aktivitas saat program dieksekusi termasuk program counter, register prosesor n Stack berisi data sementara l Function parameters, return addresses, local variables n Data section berisi global variables n Heap berisi memori yang dialokasikan secara dinamis selama running

8 3.8 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition State Proses n Sebagai sebuah proses eksekusi, akan mengubah state l new: Proses yang sedang dibuat l running: Instruksi yang sedang dieksekusi l waiting: Proses menunggu beberapa event terjadi l ready: Proses menunggu untuk ditugaskan ke prosesor l terminated: Proses selesai dieksekusi

9 3.9 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Process Control Block (PCB) Informasi yang terkait dengan setiap proses disebut task control block n Process state – running, waiting, etc n Program counter – location of instruction to next execute n CPU registers – contents of all process-centric registers n CPU scheduling information- priorities, scheduling queue pointers n Memory-management information – memory allocated to the process n Accounting information – CPU used, clock time elapsed since start, time limits n I/O status information – I/O devices allocated to process, list of open files

10 3.10 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition CPU Switch Dari Proses ke Proses

11 3.11 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Threads n Proses memiliki satu thread eksekusi l Hanya mengijinkan single task pada satu waktu l Memiliki banyak thread tiap proses 4 Memungkinkan beberapa task l Harus memiliki penyimpanan untuk detail thread, beberapa program counters di PCB

12 3.12 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Question Berikan contoh pemanfaatan multiple thread dalam satu process?

13 3.13 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Process Scheduling

14 3.14 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Process Scheduling n Maximize CPU use, quickly switch processes onto CPU for time sharing l Obj. : switch the CPU among process so frequently n Process scheduler selects among available processes for next execution on CPU n Maintains scheduling queues of processes l Job queue – set of all processes in the system l Ready queue – set of all processes residing in main memory, ready and waiting to execute l Device queues – set of processes waiting for an I/O device l Processes migrate among the various queues

15 3.15 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Ready Queue And Various I/O Device Queues

16 3.16 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Representation of Process Scheduling n Queueing diagram represents queues, resources, flows

17 3.17 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Schedulers n Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue n Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU l Sometimes the only scheduler in a system n Short-term scheduler is invoked very frequently (milliseconds)  (must be fast) n Long-term scheduler is invoked very infrequently (seconds, minutes)  (may be slow) n The long-term scheduler controls the degree of multiprogramming l degree of multiprogramming : number of process in memory n Processes can be described as either: l I/O-bound process – spends more time doing I/O than computations, many short CPU bursts l CPU-bound process – spends more time doing computations; few very long CPU bursts n Long-term scheduler strives for good process mix

18 3.18 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Addition of Medium Term Scheduling n Medium-term scheduler can be added if degree of multiple programming needs to decrease l Remove process from memory, store on disk, bring back in from disk to continue execution: swapping

19 3.19 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Multitasking in Mobile Systems n Some systems / early systems allow only one process to run, others suspended n Due to screen real estate, user interface limits iOS provides for a l Single foreground process- controlled via user interface l Multiple background processes– in memory, running, but not on the display, and with limits l Limits include single, short task, receiving notification of events, specific long- running tasks like audio playback n Android runs foreground and background, with fewer limits l Background process uses a service to perform tasks l Service can keep running even if background process is suspended l Service has no user interface, small memory use

20 3.20 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Context Switch n 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 n Context of a process represented in the PCB n Context-switch time is overhead; the system does no useful work while switching l The more complex the OS and the PCB -> longer the context switch n Time dependent on hardware support l Some hardware provides multiple sets of registers per CPU -> multiple contexts loaded at once

21 3.21 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Operations on Process

22 3.22 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Operations on Processes n System must provide mechanisms for process creation, termination, and so on as detailed next n Operation includes : l Creation of a process l Termination of a process

23 3.23 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Process Creation n Parent process create children processes, which, in turn create other processes, forming a tree of processes n Generally, process identified and managed via a process identifier (pid) Ex. : try to execute ps -el in your Linux machine n Resource sharing options l Parent and children share all resources l Children share subset of parent’s resources l Parent and child share no resources n Execution options l Parent and children execute concurrently l Parent waits until children terminate

24 3.24 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition A Tree of Processes in Linux

25 3.25 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Question : Pembuktian Jalankan beberapa program di Linux. Cek dengan perintah ps -el. Dan jawab pertanyaan berikut : l Apakah process dari program tersebut mempunyai parent? l Process mana yang menjadi parentnya?

26 3.26 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Process Creation (Cont.) n Address space l Child duplicate of parent l Child has a program loaded into it n UNIX examples fork() system call creates new process exec() system call used after a fork() to replace the process’ memory space with a new program

27 3.27 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition C Program Forking Separate Process

28 3.28 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Process Termination Process executes last statement and asks the operating system to delete it ( exit() ) Output data from child to parent (via wait() ) l Process’ resources are deallocated by operating system Parent may terminate execution of children processes ( abort() ) l Child has exceeded allocated resources l Task assigned to child is no longer required l If parent is exiting 4 Some operating systems do not allow child to continue if its parent terminates – All children terminated - cascading termination n Wait for termination, returning the pid: pid t_pid; int status; pid = wait(&status);

29 3.29 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Question n Apa yang terjadi jika parent process tidak memanggil fungsi wait() ? n Apa yang terjadi jika parent process mati sebelum child process mati? n GNOME System Monitor

30 3.30 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Multiprocess Architecture – Chrome Browser n Jalankan chrome. Cek ada berapa process chrome? n Buka beberapa tab dan akses website. Ada berapa tambahan process??

31 3.31 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Inter Process Communication (IPC)

32 3.32 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Interprocess Communication n Processes within a system may be independent or cooperating n Cooperating process can affect or be affected by other processes, including sharing data n Reasons for cooperating processes: l Information sharing l Computation speedup l Modularity l Convenience n Cooperating processes need interprocess communication (IPC) n Two models of IPC l Shared memory l Message passing

33 3.33 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Communications Models

34 3.34 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Cooperating Processes n Independent process cannot affect or be affected by the execution of another process n Cooperating process can affect or be affected by the execution of another process n Advantages of process cooperation l Information sharing l Computation speed-up l Modularity l Convenience

35 3.35 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Producer-Consumer Problem n Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process l unbounded-buffer places no practical limit on the size of the buffer l bounded-buffer assumes that there is a fixed buffer size

36 3.36 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Bounded-Buffer – Shared-Memory Solution n Shared data #define BUFFER_SIZE 10 typedef struct {... } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0; n Solution is correct, but can only use BUFFER_SIZE-1 elements

37 3.37 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Bounded-Buffer – Producer 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; }

38 3.38 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Bounded Buffer – Consumer 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 */ }

39 3.39 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Interprocess Communication – Message Passing n Mechanism for processes to communicate and to synchronize their actions n Message system – processes communicate with each other without resorting to shared variables n IPC facility provides two operations: send (message) – message size fixed or variable receive (message) n If P and Q wish to communicate, they need to: l establish a communication link between them l exchange messages via send/receive n Implementation of communication link l physical (e.g., shared memory, hardware bus) l logical (e.g., direct or indirect, synchronous or asynchronous, automatic or explicit buffering)

40 3.40 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Direct Communication n Processes must name each other explicitly: send (P, message) – send a message to process P receive (Q, message) – receive a message from process Q n Properties of communication link l Links are established automatically l A link is associated with exactly one pair of communicating processes l Between each pair there exists exactly one link l The link may be unidirectional, but is usually bi-directional

41 3.41 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Indirect Communication n Messages are directed and received from mailboxes (also referred to as ports) l Each mailbox has a unique id l Processes can communicate only if they share a mailbox n Properties of communication link l Link established only if processes share a common mailbox l A link may be associated with many processes l Each pair of processes may share several communication links l Link may be unidirectional or bi-directional

42 3.42 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Indirect Communication n Operations l create a new mailbox l send and receive messages through mailbox l destroy a mailbox n Primitives are defined as: send (A, message) – send a message to mailbox A receive (A, message) – receive a message from mailbox A

43 3.43 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Indirect Communication n Mailbox sharing l P 1, P 2, and P 3 share mailbox A l P 1, sends; P 2 and P 3 receive l Who gets the message? n Solutions l Allow a link to be associated with at most two processes l Allow only one process at a time to execute a receive operation l Allow the system to select arbitrarily the receiver. Sender is notified who the receiver was.

44 3.44 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Synchronization n Message passing may be either blocking or non-blocking n Blocking is considered synchronous l Blocking send has the sender block until the message is received l Blocking receive has the receiver block until a message is available n Non-blocking is considered asynchronous l Non-blocking send has the sender send the message and continue l Non-blocking receive has the receiver receive a valid message or null }

45 3.45 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Synchronization (Cont.) n Different combinations possible l If both send and receive are blocking, we have a rendezvous n Producer-consumer becomes trivial message next_produced; while (true) { /* produce an item in next produced */ send(next_produced); } message next_consumed; while (true) { receive(next_consumed); /* consume the item in next consumed */ }

46 3.46 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Buffering n Queue of messages attached to the link; implemented in one of three ways 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

47 3.47 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Examples of IPC Systems - POSIX n POSIX Shared Memory Process first creates shared memory segment shm_fd = shm_open(name, O CREAT | O RDWR, 0666); l Also used to open an existing segment to share it l Set the size of the object ftruncate(shm fd, 4096); l Now the process could write to the shared memory sprintf(shared memory, "Writing to shared memory");

48 3.48 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition IPC POSIX Producer

49 3.49 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition IPC POSIX Consumer

50 3.50 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Communications in Client-Server Systems

51 3.51 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Communications in Client-Server Systems n Sockets n Remote Procedure Calls n Pipes n Remote Method Invocation (Java)

52 3.52 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Sockets n A socket is defined as an endpoint for communication n Concatenation of IP address and port – a number included at start of message packet to differentiate network services on a host n The socket :1625 refers to port 1625 on host n Communication consists between a pair of sockets n All ports below 1024 are well known, used for standard services n Special IP address (loopback) to refer to system on which process is running

53 3.53 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Socket Communication

54 3.54 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Sockets in Java n Three types of sockets l Connection-oriented (TCP) l Connectionless (UDP) MulticastSocket class– data can be sent to multiple recipients n Consider this “Date” server:

55 3.55 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Pipes n Acts as a conduit allowing two processes to communicate n Issues l Is communication unidirectional or bidirectional? l In the case of two-way communication, is it half or full-duplex? l Must there exist a relationship (i.e. parent-child) between the communicating processes? l Can the pipes be used over a network?

56 3.56 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Ordinary Pipes n Ordinary Pipes allow communication in standard producer-consumer style n Producer writes to one end (the write-end of the pipe) n Consumer reads from the other end (the read-end of the pipe) n Ordinary pipes are therefore unidirectional n Require parent-child relationship between communicating processes n Windows calls these anonymous pipes n See Unix and Windows code samples in textbook

57 3.57 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Named Pipes n Named Pipes are more powerful than ordinary pipes n Communication is bidirectional n No parent-child relationship is necessary between the communicating processes n Several processes can use the named pipe for communication n Provided on both UNIX and Windows systems

58 3.58 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Pipe vs Socket n Both pipes and sockets handle byte streams, but they do it in different ways. l Pipes only exist within a specific host, and they refer to buffering between virtual files, or connecting the output / input of processes within that host. There are no concepts of packets within pipes. l Sockets packetize communication using IPv4 or IPv6; that communication can extend beyond localhost. l Socket allows more than two processes communicating n Usage: l Use pipes: 4 when you want to read / write data as a file within a specific server. If you're using C, you read() and write() to a pipe. 4 when you want to connect the output of one process to the input of another process... see popen() l Use sockets to send data between different IPv4 / IPv6 endpoints. Very often, this happens between different hosts, but sockets could be used within the same host

59 3.59 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Question Apa perbedaan pipe dan socket?

60 3.60 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Remote Procedure Calls n Remote procedure call (RPC) abstracts procedure calls between processes on networked systems l Again uses ports for service differentiation n Stubs – client-side proxy for the actual procedure on the server n The client-side stub locates the server and marshalls the parameters n The server-side stub receives this message, unpacks the marshalled parameters, and performs the procedure on the server n On Windows, stub code compile from specification written in Microsoft Interface Definition Language (MIDL) n Data representation handled via External Data Representation (XDL) format to account for different architectures l Big-endian and little-endian n Remote communication has more failure scenarios than local l Messages can be delivered exactly once rather than at most once n OS typically provides a rendezvous (or matchmaker) service to connect client and server

61 3.61 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Execution of RPC

62 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition End of Chapter 3


Download ppt "Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Bab 3: Proses."

Similar presentations


Ads by Google