* One viewfocuses on the services that the system provides; another, on the interface thatit makes available to users and programmers; a third, on its components andtheir interconnections. *
[#^jpa057kewqp|show annotation]]
* User interface. Almost all operating systems have a user interface (UI).This interface can take several forms. One is a command-line interface *
[#^5uq2nt6fuvj|show annotation]]
* Program execution. The system must be able to load a program intomemory and to run that program. *
[#^bc2eoa2qgdp|show annotation]]
* I/O operations. A running program may require I/O, which may involve afile or an I/O device. *
[#^xc8xjvy2vea|show annotation]]
* File-system manipulation. The file system is of particular interest. Obvi-ously, programs need to read and write files and directories. They alsoneed to create and delete them by name, search for a given file, andlist file information. *
[#^abltz8v3fz6|show annotation]]
* Communications. There are many circumstances in which one processneeds to exchange information with another process. *
[#^z312ogcsxd|show annotation]]
* Communications may be implementedvia shared memory *
[#^iwguwhgaqqc|show annotation]]
* Error detection. *
[#^gs9tw0vs99f|show annotation]]
* Resource allocation. When there are multiple users or multiple jobsrunning at the same time, resources must be allocated to each of them. *
[#^zrnwtsbm0v|show annotation]]
* CPU cycles, main memory, and file storage *
[#^vjhjnmqasls|show annotation]]
* I/O devices *
[#^bg5kbivlola|show annotation]]
* Accounting. We want to keep track of which users use how much andwhat kinds of computer resources. *
[#^tf26xn1pcz|show annotation]]
* Protection and security. The owners of information stored in a multiuser ornetworked computer system may want to control use of that information.When several separate processes execute concurrently, it should not bepossible for one process to interfere with the others or with the operatingsystem itself. *
[#^7orxii7nwvm|show annotation]]
* command-line interface, or command interpreter *
[#^0a4zray13o7n|show annotation]]
* On systems with multiple command interpreters to choose from, theinterpreters are known as shells. *
[#^nen5138llk|show annotation]]
* The main function of the command interpreter is to get and execute the nextuser-specified command. *
[#^rywr7739xf|show annotation]]
* In one approach, the command interpreter itself contains the code toexecute the command. *
[#^bw4d1cmghgv|show annotation]]
* An alternative approach — used by UNIX, among other operating systems— implements most commands through system programs. *
[#^nw1ddzq48a|show annotation]]
* Thus, the UNIX command to delete a filerm file.txtwould search for a file called rm, load the file into memory, and execute it withthe parameter file.txt. *
[#^0kgfwal2u32|show annotation]]
* shell scripts *
[#^sgephkk698k|show annotation]]
* System calls provide an interface to the services made available by an operatingsystem. These calls are generally available as routines written in C andC++ *
[#^64rt2tt4bcp|show annotation]]
* As you can see, even simple programs may make heavy use of theoperating system. Frequently, systems execute thousands of system callsper second *
[#^7fow0x74kdw|show annotation]]
* Typically, application developers design programs according to an applicationprogramming interface (API). The API specifies a set of functions that areavailable to an application programmer, including the parameters that arepassed to each function and the return values the programmer can expect. *
[#^1a7rklow3qb|show annotation]]
* ehind the scenes, the functions that make up an API typically invoke theactual system calls on behalf of the application programmer. For example, theWindows function CreateProcess() (which unsurprisingly is used to createa new process) actually invokes the NTCreateProcess() system call in theWindows kernel *
[#^kav29b6n4kk|show annotation]]
* For most programming languages, the run-time support system (a set offunctions built into libraries included with a compiler) provides a system-call interface that serves as the link to system calls made available by theoperating system. The system-call interface intercepts function calls in the APIand invokes the necessary system calls within the operating system *
[#^0aslas9nl48a|show annotation]]
* designing a program using an API can expect her program to compile andrun on any system that supports the same API *
[#^4bqq5vbcxtz|show annotation]]
* Three general methods are used to pass parameters to the operating system.The simplest approach is to pass the parameters in registers. *
[#^9hn5v4hx5nn|show annotation]]
* stored in a block, or table, in memory, and theaddress of the block is passed as a parameter in a register *
[#^mfhao2ui49|show annotation]]
* Parameters also can be placed,or pushed, onto the stack by the program and popped off the stack by the operating system *
[#^a82ycnzztjs|show annotation]]
* System calls can be grouped roughly into six major categories: processcontrol, file manipulation, device manipulation, information maintenance,communications, and protection. *
[#^381j4cmvdbh|show annotation]]
* To ensure the integrityof the data being shared, operating systems often provide system calls allowinga process to lock shared data. Then, no other process can access the data untilthe lock is released. *
[#^g8q3hkkdvp|show annotation]]
* The MS-DOS operatingsystem is an example of a single-tasking system. It has a command interpreterthat is invoked when the computer is started (Figure 2.9(a)). Because MS-DOSis single-tasking, it uses a simple method to run a program and does not createa new process. It loads the program into memory *
[#^hn72vbzbzqo|show annotation]]
* FreeBSD (derived from Berkeley UNIX) is an example of a multitaskingsystem. *
[#^s4wtksgl62|show annotation]]
* since FreeBSD is amultitasking system, the command interpreter may continue running whileanother program is executed *
[#^fdj62znawy4|show annotation]]
* Process control◦ end, abort◦ load, execute◦ create process, terminate process◦ get process attributes, set process attributes◦ wait for time◦ wait event, signal event◦ allocate and free memory• File management◦ create file, delete file◦ open, close◦ read, write, reposition◦ get file attributes, set file attributes• Device management◦ request device, release device◦ read, write, reposition◦ get device attributes, set device attributes◦ logically attach or detach devices• Information maintenance◦ get time or date, set time or date◦ get system data, set system data◦ get process, file, or device attributes◦ set process, file, or device attributes• Communications◦ create, delete communication connection◦ send, receive messages◦ transfer status information◦ attach or detach remote devicesFigure 2.8 Types of system calls *
[#^6le2icz34f|show annotation]]
* A system with multiple users may require us to first request()a device, to ensure exclusive use of it. After we are finished with the device, werelease() it. These functions are similar to the open() and close() systemcalls for files. *
[#^jdsmjmhzo3o|show annotation]]
* Once the device has been requested (and allocated to us), we can read(),write(), and (possibly) reposition() the device *
[#^4w0bdqo9fdl|show annotation]]
* Many system calls exist simply for the purpose of transferring informationbetween the user program and the operating system. For example, mostsystems have a system call to return the current time() and date() *
[#^stewwd9yfsj|show annotation]]
* Another set of system calls is helpful in debugging a program. Manysystems provide system calls to dump() memory. *
[#^qeun5irw3rd|show annotation]]
* There are two common models of interprocess communication: the message-passing model and the shared-memory model. In the message-passing model,the communicating processes exchange messages with one another to transferinformation. Messages can be exchanged between the processes either directlyor indirectly through a common mailbox *
[#^blqen4kx8k7|show annotation]]
* Most processes that will be receiving connections are special-purposedaemons, which are system programs provided for that purpose. They executea wait for connection() call and are awakened when a connection is made. *
[#^8hlq9xl5g4g|show annotation]]
* In the shared-memory model, processes use shared memory create()and shared memory attach() system calls to create and gain access to regionsof memory owned by other processes. *
[#^j5jt45scutb|show annotation]]
* At the lowest level ishardware. Next is the operating system, then the system programs, and finallythe application programs. System programs, also known as system utilities,provide a convenient environment for program development and execution *
[#^0g4pn6da0wko|show annotation]]
* They can be divided into these categories: *
[#^ojp7wbg8kh|show annotation]]
* File management *
[#^89rl66ogom8|show annotation]]
* Status information. Some programs simply ask the system for the date,time, amount of available memory or disk space *
[#^wcczo1un3bm|show annotation]]
* File modification *
[#^bguj6liwvxe|show annotation]]
* Programming-language support. Compilers, assemblers, debuggers, andinterpreters *
[#^dxy52w7hvad|show annotation]]
* Program loading and execution. Once a program is assembled or com-piled, it must be loaded into memory to be executed. The system mayprovide absolute loaders, relocatable loaders, linkage editors, and overlayloaders. *
[#^3lgb24a5dtd|show annotation]]
* Communications. These programs provide the mechanism for creatingvirtual connections among processes, users, and computer systems. *
[#^ymfbug3yli|show annotation]]
* Background services. All general-purpose systems have methods forlaunching certain system-program processes at boot time. *
[#^o8py4t9keoo|show annotation]]
* Constantly running system-programprocesses are known as services, subsystems, or daemons. *
[#^j9ilp47u0i|show annotation]]
* most operating systems are supplied withprograms that are useful in solving common problems or performing commonoperations. Such application programs include Web browsers, word proces-sors and text formatters *
[#^1j1k3effr9o|show annotation]]
* A system therefore consists of a collection of processes: operating-system processes executing system code and user processes executing usercode. *
[#^nyzze1czr8e|show annotation]]
* A batch system executes jobs *
[#^2b31ra10u7j|show annotation]]
* system has user programs, or tasks *
[#^1wuf6c9zh2k|show annotation]]
* a process is a program in execution *
[#^xzm0z0q63fn|show annotation]]
* includes the current activity, as represented by the value of the programcounter *
[#^cwat0f4yfic|show annotation]]
* A process generally alsoincludes the process stack, which contains temporary data (such as functionparameters, return addresses, and local variables), and a data section, whichcontains global variables. A process may also include a heap, which is memorythat is dynamically allocated during process run time. *
[#^ojrm8bjnq1|show annotation]]
* Process in memory *
[#^uhztt1as4q9|show annotation]]
* a process is an active entity,with a program counter specifying the next instruction to execute and a setof associated resources *
[#^ajrnd5zaovf|show annotation]]
* A program becomes a process when an executable fileis loaded into memory *
[#^2f2e640zjun|show annotation]]
* the sameuser may invoke many copies of the web browser program. Each of these is aseparate process *
[#^ru1m1iouwp|show annotation]]
* As a process executes, it changes state *
[#^ahcbw95xf8a|show annotation]]
* New *
[#^qxo8u5dvtif|show annotation]]
* Running *
[#^i7awysb6z9j|show annotation]]
* Waiting *
[#^sjnmceueczj|show annotation]]
* Ready *
[#^iwuddaqhuya|show annotation]]
* It is important to realizethat only one process can be running on any processor at any instant. Manyprocesses may be ready and waiting, however. *
[#^tjvif592rf|show annotation]]
* Each process is represented in the operating system by a process control block(PCB) — also called a task control block *
[#^x76rdtkode|show annotation]]
* It containsmany pieces of information associated with a specific process, including these *
[#^5ra5t3crusn|show annotation]]
* Process state *
[#^t72zt1zykf|show annotation]]
* Program counter *
[#^uh2fgq3orqd|show annotation]]
* CPU registers *
[#^pmo6tl51z3|show annotation]]
* CPU-scheduling information. *
[#^wuxv8s2ep9|show annotation]]
* Memory-management information *
[#^b0pavvsxmln|show annotation]]
* Process control block (PCB) *
[#^vxczpgpsfb9|show annotation]]
* Accounting information *
[#^1f4bgcmlj7ch|show annotation]]
* I/O status information *
[#^05el2yfijt37|show annotation]]
* single thread of control allows the process to perform only one task ata time. The user cannot simultaneously type in characters and run the spellchecker within the same process, for example *
[#^2b2o1wx90co|show annotation]]
* On a system that supports threads, the PCB is expanded to includeinformation for each thread *
[#^ir1n8z1e5et|show annotation]]
* the process scheduler selectsan available process (possibly from a set of several available processes) forprogram execution on the CPU *
[#^6f07wkpcof|show annotation]]
* As processes enter the system, they are put into a job queue, which consistsof all processes in the system *
[#^1rtb8pdsaa3|show annotation]]
* The processes that are residing in main memoryand are ready and waiting to execute are kept on a list called the ready queue. *
[#^tdmvd4dm5ho|show annotation]]
* The list of processes waiting for a particular I/O device is called adevice queue. *
[#^z9wt3fzbvo|show annotation]]
* Once the process is allocated the CPUand is executing, one of several events could occur:• The process could issue an I/O request and then be placed in an I/O queue.• The process could create a new child process and wait for the child’stermination.• The process could be removed forcibly from the CPU, as a result of an interrupt, and be put back in the ready queue. *
[#^18wlv819z6n|show annotation]]
* The operating system must select, for scheduling purposes, processesfrom these queues in some fashion. The selection process is carried out by theappropriate scheduler *
[#^iqhq7ufloc|show annotation]]
* The long-term scheduler, or jobscheduler, selects processes from this pool and loads them into memory *
[#^irls5oismvn|show annotation]]
* The short-term scheduler, or CPU scheduler, selects from amongthe processes that are ready to execute and allocates the CPU to one of them *
[#^484zt4ohqna|show annotation]]
* The short-term scheduler must select a new process for the CPUfrequently. *
[#^szlr4ry230f|show annotation]]
* The long-term scheduler executes much less frequently; minutes may sep-arate the creation of one new process and the next. The long-term schedulercontrols the degree of multiprogramming (the number of processes in mem-ory). *
[#^c0zh0esqodm|show annotation]]
* Because of the longer interval betweenexecutions, the long-term scheduler can afford to take more time to decidewhich process should be selected for execution *
[#^tj6pjp82lmh|show annotation]]
* An I/O-bound process is one that spends more of its time doing I/O thanit spends doing computations. A CPU-bound process, in contrast, generatesI/O requests infrequently, using more of its time doing computations *
[#^f3m2ssu5qea|show annotation]]
* The key idea behind a medium-term scheduler isthat sometimes it can be advantageous to remove a process from memory(and from active contention for the CPU) and thus reduce the degree ofmultiprogramming. Later, the process can be reintroduced into memory, and itsexecution can be continued where it left off. This scheme is called swapping *
[#^v2pi4kx2owh|show annotation]]
* When an interrupt occurs, the systemneeds to save the current context of the process running on the CPU so thatit can restore that context when its processing is done *
[#^97jv8c9dw3k|show annotation]]
* Generically, we perform a statesave of the current state of the CPU, be it in kernel or user mode, and then a state restore to resume operations *
[#^sm5ovnjs5lp|show annotation]]
* When a context switch occurs, the kernel saves the contextof the old process in its PCB and loads the saved context of the new processscheduled to run. *
[#^8wkvxxxa25d|show annotation]]
* One of the most common forms of remote service is the RPC paradigm *
[#^j6kkv2lwayc|show annotation]]
* In contrast to IPC messages, the messages exchanged in RPC communicationare well structured and are thus no longer just packets of data. Each message isaddressed to an RPC daemon listening to a port on the remote system, and eachcontains an identifier specifying the function to execute and the parametersto pass to that function *
[#^25rhopp0192|show annotation]]
* The semantics of RPCs allows a client to invoke a procedure on a remotehost as it would invoke a procedure locally. The RPC system hides the detailsthat allow communication to take place by providing a stub on the client side *
[#^ic1eego2ll8|show annotation]]
* many RPC systemsdefine a machine-independent representation of data. One such representationis known as external data representation (XDR). *
[#^gpwjs3ts9xt|show annotation]]
* Some systems (known as big-endian) store the most significant bytefirst, while other systems (known as little-endian) store the least significantbyte first. *
[#^7bmxg213j7x|show annotation]]
* The RPC scheme is useful in implementing a distributed file system *
[#^c0cdl5l2mh4|show annotation]]
* A pipe acts as a conduit allowing two processes to communicate *
[#^wt6z39okcr|show annotation]]
* In implementing a pipe, four issuesmust be considered: *
[#^naqx8p33lff|show annotation]]
* bidirectional communication, or is communicationunidirectional? *
[#^xyixcjtuai|show annotation]]
* If two-way communication is allowed, is it half duplex (data can travelonly one way at a time) or full duplex (data can travel in both directionsat the same time)? *
[#^4mkgro7wppi|show annotation]]
* Must a relationship (such as parent – child) exist between the communi-cating processes? *
[#^43m6j8we1jw|show annotation]]
* Can the pipes communicate over a network, or must the communicatingprocesses reside on the same machine? *
[#^dvtoa5dxh29|show annotation]]
* Ordinary pipes allow two processes to communicate in standard producer –consumer fashion: the producer writes to one end of the pipe (the write-end)and the consumer reads from the other end (the read-end). As a result, ordinarypipes are unidirectional, allowing only one-way communication *
[#^50weaqx5ahc|show annotation]]
* If two-waycommunication is required, two pipes must be used, with each pipe sendingdata in a different direction. *
[#^ve6lqtcesk|show annotation]]
* An ordinary pipe cannot be accessed from outside the process that createdit *
[#^goeoh1uldy|show annotation]]
* Named pipes provide a much more powerful communication tool. *
[#^7nxd69uvwo|show annotation]]
* Named pipes are referred to as FIFOs in UNIX systems *
[#^nel57p8i7o|show annotation]]
* Although FIFOs allow bidirectional communication, onlyhalf-duplex transmission is permitted. If data must travel in both directions,two FIFOs are typically used. Additionally, the communicating processes mustreside on the same machine. *
[#^grunnbsfrk4|show annotation]]
* A thread is a basic unit of CPU utilization; it comprises a thread ID, a program counter, a register set, and a stack. It shares with other threads belongingto the same process its code section, data section, and other operating-systemresources, such as open files and signals *
[#^0rtsr1k1dobr|show annotation]]
* A web browser might have one thread display images ortext while another thread retrieves data from the network, for example *
[#^vwsf9t3b5qk|show annotation]]
* If the web-server process ismultithreaded, the server will create a separate thread that listens for clientrequests. When a request is made, rather than creating another process, theserver creates a new thread to service the request and resume listening foradditional requests. *
[#^8mekwcrd58t|show annotation]]
* The benefits of multithreaded programming can be broken down into fourmajor categories *
[#^untbojae3jc|show annotation]]
* Responsiveness. Multithreading an interactive application may allowa program to continue running even if part of it is blocked or isperforming a lengthy operation *
[#^9n5e6028tvn|show annotation]]
* Resource sharing. Processes can only share resources through techniquessuch as shared memory and message passing *
[#^fd9q4d1x5ac|show annotation]]
* Economy. Allocating memory and resources for process creation is costly.Because threads share the resources of the process to which they belong *
[#^siac4pdo85|show annotation]]
* Scalability. *
[#^wqops4qvoab|show annotation]]
* A cooperating process is one that can affect or be affected by other processesexecuting in the system. Cooperating processes can either directly share alogical address space (that is, both code and data) or be allowed to share dataonly through files or messages. *
[#^dj5oup5rtnf|show annotation]]
* This means that one process may only partially complete executionbefore another process is scheduled. In fact, a process may be interrupted atany point in its instruction stream, and the processing core may be assignedto execute instructions of another process. *
[#^wifi1cvbjn|show annotation]]
* A situation like this, whereseveral processes access and manipulate the same data concurrently and theoutcome of the execution depends on the particular order in which the accesstakes place, is called a race condition. To guard against the race conditionabove, we need to ensure that only one process at a time can be manipulatingthe variable counter. To make such a guarantee, we require that the processesbe synchronized in some way *
[#^08iztguz59qh|show annotation]]
* Consider a system consisting of n processes{P0, P1, ..., Pn−1}. Each process has a segment of code, called a critical section,in which the process may be changing common variables, updating a table,writing a file, and so on. The important feature of the system is that, whenone process is executing in its critical section, no other process is allowed toexecute in its critical section *
[#^4tjmputk7y|show annotation]]
* The critical-section problem is to design aprotocol that the processes can use to cooperate. Each process must requestpermission to enter its critical section. The section of code implementing thisrequest is the entry section. The critical section may be followed by an exitsection. The remaining code is the remainder section *
[#^lvjwlp17cab|show annotation]]
* A solution to the critical-section problem must satisfy the following threerequirements: *
[#^jds9y50gdxk|show annotation]]
* Mutual exclusion. If process Pi is executing in its critical section, then noother processes can be executing in their critical sections. *
[#^vgd1rmcq61|show annotation]]
* Progress. If no process is executing in its critical section and someprocesses wish to enter their critical sections, then only those processesthat are not executing in their remainder sections can participate indeciding which will enter its critical section next, and this selection cannotbe postponed indefinitely.3. Bounded waiting. There exists a bound, or limit, on the number of timesthat other processes are allowed to enter their critical sections after a *
[#^l9jxzdyr0t|show annotation]]
* process has made a request to enter its critical section and before thatrequest is granted. *
[#^7ycium1ihl5|show annotation]]
* Consider as anexample a kernel data structure that maintains a list of all open files in thesystem. This list must be modified when a new file is opened or closed (addingthe file to the list or removing it from the list). If two processes were to open filessimultaneously, the separate updates to this list could result in a race condition *
[#^wqnvqp2xcp9|show annotation]]
* Two general approaches are used to handle critical sections in operatingsystems: preemptive kernels and nonpreemptive kernels. A preemptivekernel allows a process to be preempted while it is running in kernel mode. Anonpreemptive kernel does not allow a process running in kernel mode to bepreempted; *
[#^ipg5nyyvx|show annotation]]
* A preemptive kernel may be more responsive, since there is less risk that akernel-mode process will run for an arbitrarily long period before relinquishingthe processor to waiting processes *
[#^rwsl2iuhh2a|show annotation]]
* Furthermore, apreemptive kernel is more suitable for real-time programming *
[#^qia63nxem3e|show annotation]]
* Peterson’s solution is restricted to two processes that alternate executionbetween their critical sections and remainder sections. The processes arenumbered P0 and P1. *
[#^n0wokw733y|show annotation]]
* Peterson’s Solution *
[#^lgfial1rn0a|show annotation]]
Peterson’s Solution is a classic algorithm used to synchronise access to a shared resource in a concurrent programming setting, specifically in the context of two processes or threads. It provides a way to achieve mutual exclusion, ensuring that only one process can enter the critical section at a time. The algorithm is named after its creator, Gary L. Peterson.
Here’s a simplified explanation of Peterson’s Solution:
Shared Variables: The solution requires two shared variables:
turnand an array of two boolean flags,flag[2]. Each flag represents the intention of a process to enter the critical section, andturnindicates whose turn it is to enter.Entry Protocol: Before a process enters the critical section, it sets its flag to indicate its intention to enter and assigns the turn to the other process. For example, if process P0 wants to enter, it sets
flag[0] = trueandturn = 1(indicating it’s P1’s turn).Checking for Conflicts: After setting its flag and turn, the process checks if the other process also wants to enter the critical section. If the other process’s flag is true and it is their turn, a conflict occurs.
Waiting or Proceeding: If there is a conflict, the process must wait until it is its turn again. It repeatedly checks the other process’s turn until the conflict is resolved. Once the conflict is resolved, the process proceeds to enter the critical section.
Critical Section: The process can now execute its critical section, accessing the shared resource without interference from the other process. It performs the required operations and completes its task.
Exit Protocol: After exiting the critical section, the process sets its flag to false, indicating it no longer intends to enter. This allows the other process to have a chance to enter the critical section.
Mutual Exclusion: By utilizing the flags, turn variable, and the entry and exit protocols, Peterson’s Solution ensures that only one process can enter the critical section at a time. It achieves mutual exclusion by coordinating the access to the shared resource between the two processes.
It’s important to note that Peterson’s Solution assumes some properties of the underlying system, such as atomic read and write operations for shared variables. Additionally, it is specifically designed for two processes and may not be directly applicable in scenarios involving more than two processes.
While Peterson’s Solution was an important contribution to the field of concurrent programming, modern synchronization mechanisms, such as locks and semaphores, are generally preferred for achieving mutual exclusion in practical implementations due to their wider applicability and flexibility.
* operating-systems designers build software tools tosolve the critical-section problem. The simplest of these tools is the mutexlock. (In fact, the term mutex is short for mutual exclusion *
[#^5bhr27khr44|show annotation]]
* prevent race conditions. *
[#^ggw8dczmp59|show annotation]]
* aprocess must acquire the lock before entering a critical section; it releases thelock when it exits the critical section. The acquire()function acquires the lock,and the release() function releases the lock *
[#^p4nv5ccyyl|show annotation]]
* Calls to either acquire() or release() must be performed atomically. *
[#^tim49rarih|show annotation]]
* The main disadvantage of the implementation given here is that it requiresbusy waiting. While a process is in its critical section, any other process thattries to enter its critical section must loop continuously in the call to acquire() *
[#^do2h2m88p27|show annotation]]
* this type of mutex lock is also called a spinlock because the process“spins”while waiting for the lock to become available *
[#^dc06f7zagb|show annotation]]
* Busy waiting wastes CPU cycles *
[#^f608dn4c27k|show annotation]]
* Spinlocks do have an advantage, however, in that no context switch isrequired when a process must wait on a lock, and a context switch maytake considerable time *
[#^cjfmk3t6whp|show annotation]]
* A semaphore S is an integer variable that, apart from initialization, isaccessed only through two standard atomic operations: wait() and signal() *
[#^5q9v84315p|show annotation]]
* Operating systems often distinguish between counting and binary semaphores.The value of a counting semaphore can range over an unrestricted domain.The value of a binary semaphore can range only between 0 and 1. Thus, binarysemaphores behave similarly to mutex locks *
[#^38hfmqp2rs|show annotation]]
* Semaphores *
[#^mm9b5j5gm0s|show annotation]]
Semaphores are a synchronization mechanism used in concurrent programming to control access to shared resources and coordinate the execution of multiple processes or threads. They are often employed to prevent race conditions and ensure mutual exclusion.
In simple terms, a semaphore can be thought of as a counter that keeps track of the number of available resources or the state of a particular condition. It can be accessed and modified by different processes or threads concurrently. The two fundamental operations associated with semaphores are “wait” and “signal” (also known as “P” and “V” operations, respectively).
Here’s a simplified explanation of semaphores and their operations:
Semaphore Initialization: A semaphore is typically initialized with an initial value that represents the number of available resources or the desired initial state of the condition it represents. It can be a non-negative integer.
Wait (P) Operation: When a process/thread wants to access a shared resource, it needs to perform a “wait” operation on the semaphore associated with that resource. If the semaphore value is greater than 0, indicating that there are available resources, the process/thread can proceed and decrement the semaphore value by 1. If the semaphore value is 0, indicating that all resources are currently in use, the process/thread is blocked and put into a waiting state until a resource becomes available.
Signal (V) Operation: When a process/thread finishes using a shared resource, it performs a “signal” operation on the semaphore, also known as a “release” operation. This operation increments the semaphore value by 1, indicating that a resource has been released and is now available. If there are any other processes/threads waiting on the semaphore, one of them is unblocked and allowed to proceed.
By using semaphores, processes/threads can coordinate their access to shared resources and ensure exclusive access when necessary. Semaphores provide a way to impose synchronization points and enforce ordering in the execution of concurrent processes/threads.
Semaphores can also be used for other synchronization purposes beyond mutual exclusion, such as signaling events, implementing producer-consumer patterns, or managing bounded resources. Different variations of semaphores exist, including binary semaphores (with values limited to 0 and 1) and counting semaphores (with values greater than 0).
It’s worth noting that while semaphores can be a powerful tool for synchronization, their usage requires careful design to avoid potential pitfalls like deadlock or starvation. Modern programming languages and operating systems provide built-in semaphore implementations or higher-level synchronization constructs that encapsulate semaphore functionality, making it easier to handle synchronization challenges effectively.
* Classic Problems of Synchronization *
[#^4wvvka4wcxo|show annotation]]
Summary:
Bounded-Buffer Problem:
- Producer and consumer processes share data structures:
n,mutex,empty,full.nrepresents the number of buffers in the pool.mutexprovides mutual exclusion for buffer pool accesses.emptycounts the number of empty buffers.fullcounts the number of full buffers.- Producer code waits for an empty buffer, acquires mutex, adds an item to the buffer, releases mutex, and signals that a buffer is full.
- Consumer code waits for a full buffer, acquires mutex, consumes an item from the buffer, releases mutex, and signals that a buffer is empty.
Readers-Writers Problem:
- Shared database accessed by multiple processes: readers and writers.
- Writers need exclusive access to the database to write, while readers can read concurrently.
- First readers-writers problem allows readers to proceed if no writers are waiting.
- Solution includes semaphores
rw_mutex,mutex, andread_count.rw_mutexprovides mutual exclusion for writers, andmutexensures mutual exclusion forread_count.- Readers increment
read_countand wait onrw_mutexif they are the first reader.- Readers release
rw_mutexwhen exiting.- Writers wait on
rw_mutex, perform writing, and releaserw_mutex.Dining-Philosophers Problem:
- Five philosophers sharing a circular table with chopsticks.
- Philosophers alternate between thinking and eating.
- Philosophers try to pick up two chopsticks to eat.
- Solution includes semaphores
chopstick[5]representing the chopsticks.- Each philosopher waits for the left and right chopsticks, eats, and then releases the chopsticks.
- A deadlock can occur if all philosophers pick up their left chopsticks simultaneously.
- Remedies include limiting the number of philosophers at the table, requiring both chopsticks to be available before picking them up, or using an asymmetric solution.
It’s important to note that the provided summaries are based on the given text, and some details may be omitted or simplified.
* To ensure that these difficulties do not arise, we require that the writershave exclusive access to the shared database while writing to the database. Thissynchronization problem is referred to as the readers – writers problem *
[#^dv8a88lv4sh|show annotation]]
* the first readers – writers problem,requires that no reader be kept waiting unless a writer has already obtainedpermission to use the shared object. In other words, no reader should wait forother readers to finish simply because a writer is waiting *
[#^syqydblbcg|show annotation]]
* Reader – writer locks are most useful in the following situations: *
[#^hkvhustp0z4|show annotation]]
* In applications where it is easy to identify which processes only read shareddata and which processes only write shared data.• In applications that have more readers than writers. *
[#^kvaf7jxfoeo|show annotation]]
* The dining-philosophers problem is considered a classic synchronizationproblem neither because of its practical importance nor because computerscientists dislike philosophers but because it is an example of a large classof concurrency-control problems. It is a simple representation of the needto allocate several resources among several processes in a deadlock-free andstarvation-free manner. *
[#^jozzueg6wp|show annotation]]
* Although semaphores provide a convenient and effective mechanism forprocess synchronization, using them incorrectly can result in timing errorsthat are difficult to detect, since these errors happen only if particular executionsequences take place and these sequences do not always occur. *
[#^obmjbdmdldp|show annotation]]
* To deal with such errors, researchers have developed high-level languageconstructs. In this section, we describe one fundamental high-level synchro-nization construct — the monitor type *
[#^gyb8al0beuh|show annotation]]
* An abstract data type — or ADT — encapsulates data with a set of functionsto operate on that data that are independent of any specific implementationof the ADT. A monitor type is an ADT that includes a set of programmer-defined operations that are provided with mutual exclusion within the monitor *
[#^esfclzgiyv|show annotation]]
* The monitor construct ensures that only one process at a time is activewithin the monitor. *
[#^mm0it1jg5l|show annotation]]
* However, the monitorconstruct, as defined so far, is not sufficiently powerful for modeling somesynchronization schemes. For this purpose, we need to define additional syn-chronization mechanisms. These mechanisms are provided by the conditionconstruct. *
[#^lwkyr7i9ocm|show annotation]]
* Signal and wait. *
[#^18qjvswzpiz|show annotation]]
* Signal and continue *
[#^seit4d0dfrq|show annotation]]
* Monitors *
[#^fkz24tj9rl8|show annotation]]
Monitors are a high-level synchronization construct that provides a structured approach to process synchronization. They were introduced by C.A.R. Hoare and are commonly used in concurrent programming languages to ensure mutually exclusive access to shared resources.
Here are the key points about monitors:
Encapsulation: A monitor encapsulates shared data and the procedures (also known as methods or functions) that operate on that data. It combines the data and related procedures into a single unit, ensuring that access to the shared data is controlled.
Mutual Exclusion: Monitors ensure mutual exclusion by allowing only one thread or process to be active within the monitor at a given time. When a thread enters a monitor, it gains exclusive access to the shared data and can execute the monitor’s procedures without interference from other threads.
Synchronization: Monitors provide synchronization mechanisms, typically in the form of condition variables. Condition variables allow threads to wait for certain conditions to be satisfied before proceeding. Threads can signal or broadcast on condition variables to notify waiting threads about changes in the shared data.
Serialization of Access: Monitors enforce the serialization of access to shared resources. When a thread enters a monitor, it gains sole access to the shared data and is guaranteed exclusive access until it exits the monitor. This ensures that only one thread is modifying the shared data at any given time, preventing race conditions and maintaining data integrity.
Implicit Locking: Monitors provide implicit locking of the shared data. When a thread enters a monitor, it automatically acquires the lock associated with the monitor, allowing it exclusive access to the shared data. The lock is released when the thread exits the monitor, allowing other threads to enter.
Exception Handling: Monitors often provide built-in exception handling mechanisms. If an exception occurs within a monitor, the monitor automatically releases the lock and exits, ensuring that other threads can continue executing.
Overall, monitors provide a higher level of abstraction compared to lower-level synchronization primitives like semaphores or mutexes. They simplify the process of coordinating access to shared resources and help prevent common concurrency issues such as race conditions and deadlocks.
It’s worth noting that the specific implementation and features of monitors may vary depending on the programming language or framework being used.
* We say that a system is secure if its resources are used and accessedas intended under all circumstances *
[#^264e5p443su|show annotation]]
* we use the terms intruder and cracker for those attemptingto breach security. In addition, a threat is the potential for a security violation,such as the discovery of a vulnerability, whereas an attack is the attempt tobreak security. *
[#^sh1vxofkxra|show annotation]]
* Breach of confidentiality. This type of violation involves unauthorizedreading of data (or theft of information). *
[#^7iny864p4oa|show annotation]]
* Breach of integrity. This violation involves unauthorized modificationof data. *
[#^kd4zjbp42i|show annotation]]
* Breach of availability. This violation involves unauthorized destruction ofdata. *
[#^4byepm0jsuo|show annotation]]
* Theft of service. This violation involves unauthorized use of resources. *
[#^ofb1c2j2a1|show annotation]]
* Denial of service. This violation involves preventing legitimate use ofthe system. Denial-of-service (DOS *
[#^htxba4hoyog|show annotation]]
* The most common is masquerading, in which one participant ina communication pretends to be someone else (another host or anotherperson). By masquerading, attackers breach authentication, *
[#^ihlt9qj9q1q|show annotation]]
* A replay attack consists of the malicious or fraudulent repeat of avalid data transmission *
[#^zl5y0ce0d9|show annotation]]
* man-in-the-middle attack, in which an attacker sits in the dataflow of a communication, masquerading as the sender to the receiver, andvice versa. *
[#^qiz8gzdpezs|show annotation]]
* session hijacking, in which an active communication session isintercepted. *
[#^d9582xo5hyh|show annotation]]
* To protect a system, we must take security measures at four levels: *
[#^xooe7royf6|show annotation]]
* Physical *
[#^0pylhm55xies|show annotation]]
* Human *
[#^23nuryhw7op|show annotation]]
* Operating system *
[#^h6k5ut7wspc|show annotation]]
* Network *
[#^3oj27iktm4e|show annotation]]
* while it is useful to log into a system without authorization, it is quite a lot more useful to leave behinda back-door daemon that provides information or allows easy access even ifthe original exploit is blocked *
[#^04o36o8sivx|show annotation]]
* A code segment that misuses its environment is called a Trojan horse *
[#^xqdw0m2h1f|show annotation]]
* A variation of the Trojan horse is a program that emulates a login program.An unsuspecting user starts to log in at a terminal and notices that he hasapparently mistyped his password. He tries again and is successful. Whathas happened is that his authentication key and password have been stolenby the login emulator, which was left running on the terminal by the thief *
[#^n9i2ux3bcuj|show annotation]]
* Spyware sometimesaccompanies a program that the user has chosen to install. *
[#^1ib28dijhdh|show annotation]]
* The goal of spyware is to download ads to displayon the user ’s system, create pop-up browser windows when certain sites arevisited, or capture information from the user ’s system and return it to a centralsite. *
[#^fu96xl5yq4q|show annotation]]
* covert channels, in which surreptitious communication occurs. For example,the installation of an innocuous-seeming program on a Windows system couldresult in the loading of a spyware daemon *
[#^0nsb2g999d8|show annotation]]
* The designer of a program or system might leave a hole in the software that onlyshe is capable of using. This type of security breach (or trap door) was shown inthe movie War Games. For instance, the code might check for a specific user ID orpassword, and it might circumvent normal security procedures *
[#^ij5nzvk0vv|show annotation]]
* Trap doors pose a difficult problem because, to detect them, we have toanalyze all the source code for all components of a system *
[#^j2zaxcsirq|show annotation]]
* This scenario is known as a logicbomb. A programmer, for example, might write code to detect whether hewas still employed; if that check failed, a daemon could be spawned to allowremote access, or code could be launched to cause damage to the site *
[#^ifwt5nkm1v|show annotation]]
* A virus is a fragment of code embed-ded in a legitimate program. *
[#^4nbsf021nwm|show annotation]]
* UNIX and other multiuser operating systems generally are not susceptibleto viruses because the executable programs are protected from writing by theoperating system. *
[#^4u27qb8ay0h|show annotation]]
* Once a virus reaches a target machine, a programknown as a virus dropper inserts the virus into the system. The virus dropperis usually a Trojan horse, executed for other reasons but installing the virusas its core activity. Once installed, the virus may do any one of a number ofthings. *
[#^i9zlpbbgudo|show annotation]]
* File *
[#^7yjxzguiyhk|show annotation]]
* Boot *
[#^16eyc64rddc|show annotation]]
* Macro *
[#^dudurn129jg|show annotation]]
* Source code *
[#^02zcfwm2bvh3|show annotation]]
* Polymorphic. A polymorphic virus changes each time it is installed toavoid detection by antivirus software. *
[#^e2z3v5gnekc|show annotation]]
* Encrypted *
[#^hd0gmgh69ei|show annotation]]
* Stealth *
[#^w1wvaz6fq|show annotation]]
* Tunneling. This virus attempts to bypass detection by an antivirus scannerby installing itself in the interrupt-handler chain *
[#^01emkpa3oie2|show annotation]]
* Multipartite. A virus of this type is able to infect multiple parts of a system *
[#^9c30sfmuw76|show annotation]]
* Armored. An armored virus is coded to make it hard for antivirusresearchers to unravel and understand. *
[#^ggszka4u5gu|show annotation]]
* A worm is a process that uses the spawn mechanism to duplicate itself. Theworm spawns copies of itself, using up system resources and perhaps lockingout all other processes *
[#^iguy2ynt81h|show annotation]]
* The worm was made up of two programs, a grappling hook (also calleda bootstrap or vector) program and the main program. *
[#^46sgro6ox58|show annotation]]
* Port scanning is not an attack but rather a means for a cracker to detecta system’s vulnerabilities to attack. Port scanning typically is automated,involving a tool that attempts to create a TCP/IP connection to a specific portor a range of ports. *
[#^059fezbmgcmh|show annotation]]
* As mentioned earlier, denial-of-service attacks are aimed not at gaininginformation or stealing resources but rather at disrupting legitimate use ofa system or facility. *
[#^8zu8skrmhtv|show annotation]]
* Denial-of-service attacks are generally network based. They fall into twocategories. Attacks in the first category use so many facility resources that,in essence, no useful work can be done *
[#^29ftog82dm9|show annotation]]
* he second category involves disrupting the networkof the facility. *
[#^ydxmp0nefan|show annotation]]
* Generally, it is impossible to prevent denial-of-service attacks. The attacksuse the same mechanisms as normal operation. Even more difficult to preventand resolve are distributed denial-of-service (DDOS) attacks. These attacksare launched from multiple sites at once, toward a common target, typicallyby zombies. *
[#^b3q40ts4yxp|show annotation]]
* An encryption algorithm consists of the following components:• A set K of keys.• A set M of messages.• A set C of ciphertexts.• An encrypting function E : K → (M → C). That is, for each k ∈ K, Ek is afunction for generating ciphertexts from messages. Both E and Ek for any kshould be efficiently computable functions. Generally, Ek is a randomizedmapping from messages to ciphertexts.• A decrypting function D : K → (C → M). That is, for each k ∈ K, Dk is afunction for generating messages from ciphertexts. Both D and Dk for anyk should be efficiently computable functions. *
[#^i2etyootapp|show annotation]]
* In a symmetric encryption algorithm, the same key is used to encrypt and todecrypt. Therefore, the secrecy of k must be protected. *
[#^hw5pjksh3vo|show annotation]]
* RC4 is perhaps the most common stream cipher. A stream cipher isdesigned to encrypt and decrypt a stream of bytes or bits rather than a block *
[#^pw4nz4zihr|show annotation]]
* In an asymmetric encryption algorithm, there are different encryption anddecryption keys. An entity preparing to receive encrypted communicationcreates two keys and makes one of them (called the public key) available toanyone who wants it. Any sender can use that key to encrypt a communication,but only the key creator can decrypt the communication *
[#^wsdsu39ck2m|show annotation]]
* As an example of how public-key encryption works, we describe analgorithm known as RSA *
[#^5q1rhdfl5he|show annotation]]
* In RSA, ke is the public key, and kd is the private key *
[#^nnhoxjlmz3|show annotation]]
* Advantages of Distributed Systems *
[#^6m950e3cy55|show annotation]]
Advantages of Distributed Systems:
- Resource Sharing:
Different sites in a distributed system can share resources available at remote sites.
Examples include sharing files, using distributed databases, accessing specialized hardware devices, and performing various operations.
- Computation Speedup:
Distributed systems allow partitioning of computations into subcomputations that can run concurrently.
Subcomputations can be distributed among different sites, enabling faster computation.
Load sharing or job migration can be performed to balance the workload among sites.
- Reliability:
If one site fails in a distributed system, the remaining sites can continue operating, enhancing system reliability.
Multiple large autonomous installations can withstand failures without affecting the entire system.
Redundancy in hardware and data helps the system continue functioning even if some sites fail.
Failures need to be detected, appropriate actions must be taken, and failed sites can be reintegrated after recovery.
- Communication:
- Distributed systems facilitate information exchange between connected sites.
- Messages are passed between systems, allowing various functions like file transfer, login, mail, and remote procedure calls.
- Collaboration and coordination between geographically distant users become possible.
Overall Benefits of Distributed Systems:
- Downsizing trend: Many companies are replacing mainframes with networks of workstations or personal computers.
- Better functionality and cost-effectiveness.
- More flexibility in resource allocation and facility expansion.
- Improved user interfaces and easier maintenance.
* A distributed system is a collection of loosely coupled nodes interconnectedby a communication network. *
[#^fq6ncd3ngcv|show annotation]]
* In general,resource sharing in a distributed system provides mechanisms for sharingfiles at remote site *
[#^uuqj2ud8d|show annotation]]
* The subcomputations can berun concurrently and thus provide computation speedup *
[#^qlwespl1jz|show annotation]]
* If one site fails in a distributed system, the remaining sites can continueoperating, giving the system better reliability *
[#^ceqo28ylw7t|show annotation]]
* When several sites are connected to one another by a communication network,users at the various sites have the opportunity to exchange information. Ata low level, messages are passed between systems, much as messages arepassed between processes in the single-computer message system *
[#^ziudqq9buc|show annotation]]
Nav