Download presentation
Presentation is loading. Please wait.
1
Lecture #3 프로세스(Process)
2
강의 내용 1. 프로세스(Process) 란? 2. 프로세스 상태(Process State) 모델
1) 2-상태 프로세스 상태 모델 2) 5-상태 프로세스 상태 모델 3) 7-상태 프로세스 상태 모델 3. 운영체제 제어 정보 구조체 4. 프로세스 이미지 및 제어 블록(PCB) 5. 프로세스 스케줄링 & 프로세스 전환 6. 운영체제 실행 방식 7. Unix SVR4에서의 프로세스 관리 Operating System
3
The OS Manages Execution of Applications
Resources are made available to multiple applications The processor is switched among multiple application The processor and I/O devices can be used efficiently
4
프로세스(Process)(1) “Task(태스크)” 실행중인 프로그램(A program in execution)
프로그램의 실행 메모리 이미지 An instance of a program running on a computer 프로그램 – 수동적인 실체 프로세스 – 능동적인 실체 : trace 가능 윈도우 환경에 아래아한글 프로그램을 두 번 실행하는 경우: 하드 디스크에 저장된 아래아한글 프로그램: 프로그램 두개의 아래아한글 윈도우: 프로세스 Operating System
5
프로세스(Process)(2) 모든 multitasking OS는 ‘프로세스’ 개념 을 바탕으로 동작한다
프로세스는 시분할 시스템의 작업 단위 The entity that can be assigned to and executed on a processor Operating System
6
프로세스(Process)(3) 주기억장치 보조기억장치 운영체재 아래아한글 프로세스 1 아래아한글 프로그램 아래아한글
프로세스 2 Operating System
7
Process Elements (1) A process is comprised of:
Program code (possibly shared) A set of data A number of attributes describing the state of the process
8
Process Elements (2) While the process is running it has a number of elements including Identifier State Priority Program counter Memory pointers Context data I/O status information Accounting information Mention that this list is not necessarily complete, and may include optional elements (e.g. not all OS’s may need a process to have accounting information)
9
Process Control Block Contains the process elements
Created and manage by the operating system Allows support for multiple processes Emphasise that the Process Control Block contains sufficient information so that it is possible to interrupt a running process and later resume execution as if the interruption had not occurred.
10
Trace of the Process (1) The behavior of an individual process is shown by listing the sequence of instructions that are executed This list is called a Trace Dispatcher is a small program which switches the processor from one process to another
11
Trace of the Process (2) Dispatcher (short-term scheduler)
프로세서(CPU)를 하나의 프로세스에서 다른 프로세스로 옮겨주는 OS 프로그램 스케줄링 알고리즘을 바탕으로 다음에 실행될 프로세스를 결정한다 하나의 프로세스가 CPU 시간을 독점하는 것을 막는다 프로세스 A에서 프로세스 B 로 실행 전환하는 동안에 CPU는 dispatcher 프로그램을 실행한다 Operating System
12
Process Execution Consider three processes being executed
All are in memory (plus the dispatcher) Lets ignore virtual memory for this. Operating System
13
Trace from processes point of view
Each process runs to completion Animated slide Wipes down to give impression of process progression
14
Trace from Processors point of view
Timeout Timeout Timeout I/O Animated slide Explain the scenario then click for the animation The shaded areas represent code executed by the dispatcher. The same sequence of instructions is executed by the dispatcher in each instance because the same functionality of the dispatcher is being executed. We assume that the OS only allows a process to continue execution for a maximum of six instruction cycles, after which it is interrupted; this prevents any single process from monopolizing processor time. Animate here The first six instructions of process A are executed, followed by a time-out and the execution of some code in the dispatcher, which executes six instructions before turning control to process B2. After four instructions are executed, process B requests an I/O action for which it must wait. Therefore, the processor stops executing process B and moves on, via the dispatcher, to process C. After a time-out, the processor moves back to process A. When this process times out, process B is still waiting for the I/O operation to complete, so the dispatcher moves on to process C again.
15
프로세스 상태(Process States)(1)
characterize the behaviour of processes 하나의 프로세스가 생성되어 종료하는 동안 여러 상태를 전이하며 실행된다 2-상태 프로세스 모델 Running state / Not-Running state Not Running Enter Dispatch Pause Exit (a) State transition diagram Operating System
16
프로세스 상태(Process States)(2)
2-상태 프로세스 모델 – 큐잉 모델 Processor Enter Queue Dispatch Exit Pause (b) Queuing diagram Operating System
17
Process Birth and Death
Creation Termination New batch job Normal Completion Interactive Login Memory unavailable Created by OS to provide a service Protection error Spawned by existing process Operator or OS Intervention There are many reasons why a process may be created or terminated. See tables 3.1 and 3.2 for more
18
Process Creation The OS builds a data structure to manage the process
Traditionally, the OS created all processes But it can be useful to let a running process create another This action is called process spawning Parent Process is the original, creating, process Child Process is the new process Typically, the “related” processes need to communicate and cooperate with each other. Achieving this cooperation is a difficult task for the programmer; discussed further in Chapter 5.
19
Process Termination There must be some way that a process can indicate completion. This indication may be: A HALT instruction generating an interrupt alert to the OS. A user action (e.g. log off, quitting an application) A fault or error Parent process terminating
20
5-상태 프로세스 모델 (1) 5-상태 프로세스 모델: The Running state(실행)
CPU를 할당받아 명령어를 실행중인 상태 The Ready state(준비) CPU를 할당받기 위해 준비중인 상태 The Blocked(Waiting) state(대기) 어떤 사건이 일어나기를 기다리고 있는 상태(대기상태) (ex: the completion of an I/O) Operating System
21
5-상태 프로세스 모델 (2) The New state(생성) 프로세스 생성 단계
운영체제는 프로세스 생성에 필요한 작업을 수행: 프로세스 식별자(process identifier) 생성 프로세스 테이블(process table) 항목 생성 프로세스 실행이 아직 허용되지 않은 상태 프로그램이 메모리에 적재되지 않은 상태 제한된 자원에 대한 승인 제어 Operating System
22
5-상태 프로세스 모델 (3) The Exit(Terminated) state(종료)
프로그램 실행 종료 단계 프로그램이 메모리에서 해제된 상태 프로세스에 대한 테이블 정보 및 기타 정보는 잠시 유지된다 예: accounting program that cumulates resource usage for billing the users 데이터가 더 이상 필요 없는 경우에 프로세스가 삭제된다 Operating System
23
5-상태 프로세스 모델 (4) 프로세스 상태 전이 Ready Running
dispatcher가 실행하기 위해 하나의 프로세스를 선택하면 프로세스는 ready 상태에서 running 상태로 전환된다 Running Ready running 상태의 프로세스에 할당된 time slot이 끝난 경우 더 높은 우선순위 프로세스가 ready 상태로 들어오는 경우 Operating System
24
5-상태 프로세스 모델 (5) 프로세스 상태전이 (계속) Running Blocked
실행중인 프로세스가 기다려야 하는 사건(event)을 요구하는 경우: 아직 준비되지 않은 자원에 대한 접근 입출력 동작을 시작하고 종료를 기다리는 경우 다른 프로세스가 입력을 제공하기를 기다리는 경우(IPC) Blocked Ready 기다리는 사건이 발생하였을 경우 Operating System
25
5-상태 프로세스 모델 (6) Ready to exit: A parent may terminate a child process
Operating System
26
5-상태 프로세스 모델 (7) 5-상태 프로세스 모델 – 큐잉모델 2개의 큐를 사용
In the simplest solution, this model would require an additional queue for the blocked processes. But when an event occurs the dispatcher would have to cycle through the entire queue to see which process is waiting for the event. This can cause huge overhead when their may be 100’s or 1000’s of processes
27
5-상태 프로세스 모델 (8) 5-상태 프로세스 모델 – 큐잉모델 다수의 블록 큐를 사용
More efficient to have a separate ‘blocked’ queue for each type of event.
28
7-상태 프로세스 모델 (1) “suspend(일시정지)” 상태가 필요 스와핑(swapping)의 필요성
5-상태 프로세스 모델에서는 대기(blocked) 상태의 프로세스까지 주기억장치를 점유한다 가상메모리를 사용하는 경우에도 주기억장치에 너무 많은 프로세스를 올리는 경우 시스템 성능을 저하 시킨다 “suspend(일시정지)” 상태가 필요 대기 상태의 프로세스를 디스크 장치로 스와핑(swapping) Blocked Suspend 디스크 장치로 스와핑된 blocked processes Ready Suspend 디스크 장치로 스와핑된 ready processes Operating System
29
7-상태 프로세스 모델 (2) 추가 프로세스 상태전이 Blocked Blocked Suspend
메모리 상의 모든 프로세스가 대기 상태가 되면 새로운 준비 상태의 프로세스를 가져오기 위한 메모리 공간을 확보하고자 하는 경우 pp. 141, 표 3.4 참조 Blocked Suspend Ready Suspend 기다리던 사건이 일어나는 경우 Ready Suspend Ready 메모리에 더 이상 준비 상태의 프로세스가 없는 경우 Ready Ready Suspend (unlikely) 대기 상태의 프로세스가 없는데 메모리 공간이 필요한 경우 Operating System
30
7-상태 프로세스 모델 (3) Operating System
31
Reason for Process Suspension
Comment Swapping The OS needs to release sufficient main memory to bring in a process that is ready to execute. Other OS Reason OS suspects process of causing a problem. Interactive User Request e.g. debugging or in connection with the use of a resource. Timing A process may be executed periodically (e.g., an accounting or system monitoring process) and may be suspended while waiting for the next time. Parent Process Request A parent process may wish to suspend execution of a descendent to examine or modify the suspended process, or to coordinate the activity of various descendants. The comments are summarized due to space on slide Table 3.3 Reasons for Process Suspension
32
Requirements of an Operating System
Process Execution Interleaving - Interleave the execution of multiple processes to maximize processor utilization while providing reasonable response time Resource Allocation - Allocate resources to processes Interprocess Communication - Support interprocess communication and user creation of processes Operating System
33
Processes and Resources
Operating System
34
Operating System Control Structures
Information about the current status of each process and resource for the OS to manage processes and resources Tables are constructed for each entity the operating system manages Operating System
35
OS Control Tables Operating System
36
Memory Tables Allocation of main memory to processes
Allocation of secondary memory to processes Protection attributes for access to shared memory regions Information needed to manage virtual memory Operating System
37
I/O Tables I/O device is available or assigned Status of I/O operation
Location in main memory being used as the source or destination of the I/O transfer Operating System
38
File Tables Existence of files Location on secondary memory
Current Status Attributes Sometimes this information is maintained by a file management system Operating System
39
Process Table Where process is located
Attributes in the process control block Program Data Stack Operating System
40
Process Image (1) Operating System
41
Process Image (2) User program User data Stack(s)
for procedure calls and parameter passing 프로세스 제어 블록(Process Control Block: PCB) 운영체제가 프로세스를 관리하기 위해 필요한 정보: Process identification information Processor state information Process control information Operating System
42
Process Image (3) Operating System
43
Process Image (4) 각각의 프로세스 이미지는 가상 메모리 상에 존재한다
연속적인 메모리 공간에 할당될 필요가 없다 전용 메모리와 공유 메모리 둘 다 사용한다 프로세스 이미지의 주소는 Primary Process Table의 프로세스별 항목에 저장한다 운영체제가 프로세스를 관리하기 위해서 프로세스 이미지 전부를 메모리에 올릴 필요는 없다 Operating System
44
프로세스 제어 블록(PCB)(1) 프로세스 식별 정보 유일한 프로세스 식별자 (always)
primary process table에 대한 인덱스 사용자 식별자 작업을 실행시킨 사용자에 대한 식별 정보 부모 프로세스 식별자 현재 프로세스를 생성하는 프로세스(Parent Process)의 식별자 Operating System
45
프로세스 제어 블록(PCB)(2) 프로세스 상태 정보 Contents of processor registers
프로세스 실행 상태를 표시하는 정보 주로 프로세서(CPU) 상태 정보 Contents of processor registers User-visible registers Control and status registers Stack pointers Program status word (PSW) processor status information Operating System
46
Pentium II EFLAGS Register
All processor designs include a register or set of registers, often known as the program status word (PSW), that contains status information. The PSW typically contain condition codes plus other status information. A good example of a processor status word is that on Pentium processors, referred to as the EFLAGS register This structure is used by any OS (including UNIX and Windows) running on a Pentium processor. Also see Table 3.6
47
프로세스 제어 블록(PCB)(3) 프로세스 제어 정보 스케줄링 및 상태 정보 데이터 구조 정보
프로세스 스케줄링 및 제어에 필요한 정보 스케줄링 및 상태 정보 프로세스 상태 (ie: running, ready, blocked...) 프로세스 우선순위 대기 상태에 있는 사건 (if blocked) 데이터 구조 정보 process queues parent-child relationships other structures etc. Operating System
48
프로세스 제어 블록(PCB)(4) 프로세스 제어 정보(계속)
프로세스간 통신 정보 may hold flags and signals for IPC 프로세스 특권 정보 Ex: access to certain memory locations... 메모리 관리 정보 pointers to segment/page tables assigned to this process 자원 소유 및 이용 정보 resource in use: open files, I/O devices... history of usage (of CPU time, I/O...) Operating System
49
Queues as linked lists of PCBs
Operating System
50
프로세스 스케줄링 실행중이 아닌 프로세스는 준비 큐(queue) 또는 대기 큐에서 상태 전이를 기다린다
준비 큐에서는 다음에 실행한 프로세스를 결정한다 - short-term scheduling 대기 큐에서는 각 프로세스가 사건이 발생하기를 기다린다 중지(suspend) 상태의 프로세스 중에서 준비 상태로 전환할 프로세스를 결정한다 - mid-term scheduling Operating System
51
큐잉 원리 – Using Two Queues Operating System
52
큐잉 원리 – Using Multiple Queues
Operating System
53
프로세스 전환(Process Switching)(1)
운영체제가 CPU 제어권을 할당 받을 때마다 프로세스 전환이 발생한다 Supervisor Call(시스템 호출) explicit request by the program (ex: file open). The process will probably be blocked Trap An error resulted from the last instruction. It may cause the process to be moved to the Exit state Interrupt the cause is external to the execution of the current instruction. Operating System
54
프로세스 전환(Process Switching)(2)
인터럽터 예: Clock process has expired his time slice and is transferred to the ready state I/O first move the processes waiting for this event to the ready (or ready suspend) state then resume the running process or choose a process of higher priority Memory fault memory address is in virtual memory so it must bring corresponding block into main memory thus move this process to a blocked state (waiting for the I/O to complete) Operating System
55
프로세스 전환 절차 “문맥 교환(Context Switch)”
프로그램 카운터와 다른 레지스터을 포함한 프로세서 문맥을 저장한다 현재 수행중인 프로세스의 PCB을 새로운 상태 정보와 관련 정보로 수정한다 PCB을 적절한 큐에 이동한다 실행을 위해 다른 프로세스를 선택한다 선택된 프로세스의 PCB를 수정한다 선택된 프로세스의 PCB로부터 새로운 프로세서 문맥을 적재한다 Operating System
56
프로세스 생성(Process Creation)
일괄작업(batch job) 실행 User logs on 사용자에게 제공되는 OS 서비스(ex: printing a file) 하나의 프로세스에서 새로운 프로세스로의 확장 사용자 프로그램은 여러 개의 프로세스을 생성할 수 있다 부모 프로세스(Parent Process) / 자식 프로세스(Child Process) Operating System
57
프로세스 생성 동작 유일한 프로세스 식별자를 할당 프로세스 이미지를 위한 메모리 영역을 할당
PCB(process control block) 초기화 많은 초기값 지정(ex: state is New, no I/O devices or files...) 이외는 부모 프로세스 내용을 복사 적절한 연결을 설정 예: 새로운 프로세스를 스케줄링 큐에 추가한다 Operating System
58
프로세스 종료(Process Termination)
일괄작업(Batch job)에서의 Halt instruction 사용자 로그오프(User logs off) 프로세스에 대한 종료 요구(Termination Request) Error and fault conditions Operating System
59
프로세스 종료 요구(1) Normal completion Time limit exceeded Memory unavailable
Memory bounds violation Protection error example: write to read-only file Arithmetic error Time overrun process waited longer than a specified maximum for an event Operating System
60
프로세스 종료 요구(2) I/O failure Invalid instruction Privileged instruction
happens when try to execute data Privileged instruction Operating system intervention such as when deadlock occurs Parent request to terminate one offspring Parent terminates, so child processes terminate Operating System
61
Is the OS a Process? If the OS is just a collection of programs and if it is executed by the processor just like any other program, is the OS a process? If so, how is it controlled? Who (what) controls it? If the OS is just a collection of programs and if it is executed by the processor just like any other program, is the OS a process? If so, how is it controlled? These interesting questions have inspired a number of design approaches.
62
Execution of the Operating System
63
Non-process Kernel Execute kernel outside of any process
The concept of process is considered to apply only to user programs Operating system code is executed as a separate entity that operates in privileged mode The key point is that the concept of process is considered to apply only to user programs. The operating system code is executed as a separate entity that operates in privileged mode. Common on many older operating systems, Execute the kernel of the OS outside of any process. When the currently running process is interrupted or issues a supervisor call, the mode context of this process is saved and control is passed to the kernel. The OS has its own region of memory to use and its own system stack for controlling procedure calls and returns. The OS can perform any desired functions and restore the context of the interrupted process, which causes execution to resume in the interrupted user process. Or, the OS can complete the function of saving the environment of the process and proceed to schedule and dispatch another process. Whether this happens depends on the reason for the interruption and the circumstances at the time.
64
Execution Within User Processes
Operating system software within context of a user process No need for Process Switch to run OS routine Common with operating systems on smaller computers (PCs, workstations) Execute virtually all OS software in the context of a user process The view is that the OS is primarily a collection of routines that the user calls to perform various functions, executed within the environment of the user’s process. At any given point, the OS is managing n process images. Each image includes not only the regions illustrated, but also program, data, and stack areas for kernel programs. Figure 3.16 suggests a typical process image structure for this strategy. A separate kernel stack is used to manage calls/returns while the process is in kernel mode. Operating system code and data are in the shared address space and are shared by all user processes. When an interrupt, trap, or supervisor call occurs, the processor is placed in kernel mode and control is passed to the OS. To pass control from a user program to the OS, the mode context is saved and a mode switch takes place to an operating system routine. However, execution continues within the current user process. Thus, a process switch is not performed, just a mode switch within the same process. If the OS, upon completion of its work, determines that the current process should continue to run, then a mode switch resumes the interrupted program within the current process. This is one of the key advantages of this approach: A user program has been interrupted to employ some operating system routine, and then resumed, and all of this has occurred without incurring the penalty of two process switches.
65
Process-based Operating System
Implement the OS as a collection of system process Another alternative is to implement the OS as a collection of system processes. As in the other options, the software that is part of the kernel executes in a kernel mode. In this case, however, major kernel functions are organized as separate processes. Again, there may be a small amount of process switching code that is executed outside of any process. This approach has several advantages. It imposes a program design discipline that encourages the use of a modular OS with minimal, clean interfaces between the modules. Some noncritical operating system functions are conveniently implemented as separate processes. Implementing the OS as a set of processes is useful in a multiprocessor or multicomputer environment, in which some of the operating system services can be shipped out to dedicated processors, improving performance.
66
Security Issues An OS associates a set of privileges with each process. Highest level being administrator, supervisor, or root, access. A key security issue in the design of any OS is to prevent anything (user or process) from gaining unauthorized privileges on the system Especially - from gaining root access. An OS associates a set of privileges with each process. These privileges dictate what resources the process may access, including regions of memory, files, privileged system instructions, and so on. Typically, a process that executes on behalf of a user has the privileges that the OS recognizes for that user. A system or utility process may have privileges assigned at configuration time. Typically the highest level of privilege is referred to as administrator, supervisor, or root, access. Root access provides access to all the functions and services of the operating system. With root access, a process has complete control of the system and can add or changes programs and files, monitor other processes, send and receive network traffic, and alter privileges. A key security issue in the design of any OS is to prevent, or at least detect, attempts by a user or a piece of malicious software (malware) from gaining unauthorized privileges on the system and, in particular, from gaining root access.
67
System access threats Intruders Malicious software (malware)
Masquerader (outsider) Misfeasor (insider) Clandestine user (outside or insider) Malicious software (malware) Intruder: Masquerader: An individual who is not authorized to use the computer and who penetrates a system’s access controls to exploit a legitimate user’s account Misfeasor: A legitimate user who accesses data, programs, or resources for which such access is not authorized, or who is authorized for such access but misuses his or her privileges Clandestine user: An individual who seizes supervisory control of the system and uses this control to evade auditing and access controls or to suppress audit collection
68
Countermeasures: Intrusion Detection
Intrusion detection systems are typically designed to detect human intruder and malicious software behaviour. May be host or network based Intrusion detection systems (IDS) typically comprise Sensors Analyzers User Interface RFC 2828 defines an IDS as A security service that monitors and analyzes system events for the purpose of finding, and providing real-time or near-real-time warning of, attempts to access system resources in an unauthorized manner. Host-based IDS: Monitors the characteristics of a single host and the events occurring within that host for suspicious activity Network-based IDS: Monitors network traffic for particular network segments or devices and analyzes network, transport, and application protocols to identify suspicious activity An IDS comprises three logical components: Sensors: Sensors are responsible for collecting data. The input for a sensor may be any part of a system that could contain evidence of an intrusion. Types of input to a sensor include network packets, log files, and system call traces. Sensors collect and forward this information to the analyzer. Analyzers: Analyzers receive input from one or more sensors or from other analyzers. The analyzer is responsible for determining if an intrusion has occurred. The output of this component is an indication that an intrusion has occurred. The output may include evidence supporting the conclusion that an intrusion occurred. The analyzer may provide guidance about what actions to take as a result of the intrusion. User interface: The user interface to an IDS enables a user to view output from the system or control the behaviour of the system. In some systems, the user interface may equate to a manager, director, or console component.
69
Countermeasures: Authentication
Two Stages: Identification Verification Four Factors: Something the individual knows Something the individual possesses Something the individual is (static biometrics) Something the individual does (dynamic biometrics) RFC 2828 defines user authentication as follows: The process of verifying an identity claimed by or for a system entity. An authentication process consists of two steps: Identification step: Presenting an identifier to the security system. (Identifiers should be assigned carefully, because authenticated identities are the basis for other security services, such as access control service.) Verification step: Presenting or generating authentication information that corroborates the binding between the entity and the identifier. Be prepared to elaborate on each factor with examples. Point out that each has weaknesses, but strength comes with multiple factors (e.g. password and token) Four Factors: Something the individual knows: Examples include a password, a personal identification number (PIN), or answers to a prearranged set of questions. • Something the individual possesses: Examples include electronic keycards, smart cards, and physical keys. This type of authenticator is referred to as a token. • Something the individual is (static biometrics): Examples include recognition by fingerprint, retina, and face. • Something the individual does (dynamic biometrics): Examples include recognition by voice pattern, handwriting characteristics, and typing rhythm.
70
Countermeasures: Access Control
A policy governing access to resources A security administrator maintains an authorization database The access control function consults this to determine whether to grant access. An auditing function monitors and keeps a record of user accesses to system resources. Access control implements a security policy that specifies who or what (e.g., in the case of a process) may have access to each specific system resource and the type of access that is permitted in each instance. A security administrator maintains an authorization database that specifies what type of access to which resources is allowed for this user. The access control function consults this database to determine whether to grant access. An auditing function monitors and keeps a record of user accesses to system resources.
71
Countermeasures: Firewalls
Traditionally, a firewall is a dedicated computer that: interfaces with computers outside a network has special security precautions built into it to protect sensitive files on computers within the network. Firewalls can be an effective means of protecting a local system or network of systems from network-based security threats while at the same time affording access to the outside world via wide area networks and the Internet. Traditionally, a firewall is a dedicated computer that interfaces with computers outside a network and has special security precautions built into it in order to protect sensitive files on computers within the network. It is used to service outside network, especially Internet, connections and dial-in lines. Personal firewalls that are implemented in hardware or software, and associated with a single workstation or PC, are also common.
72
Process Management in Unix SVR4
Uses the model of fig3.15b where most of the OS executes in the user process System Processes - Kernel mode only User Processes User mode to execute user programs and utilities Kernel mode to execute instructions that belong to the kernel. UNIX System V makes use of a simple but powerful process facility that is highly visible to the user. System processes run in kernel mode and execute operating system code to perform administrative and housekeeping functions, such as allocation of memory and process swapping. User processes operate in: user mode to execute user programs and utilities in kernel mode to execute instructions that belong to the kernel. A user process enters kernel mode by issuing a system call, when an exception (fault) is generated, or when an interrupt occurs.
73
UNIX Process State Transition Diagram
A total of nine process states are recognized by the UNIX SVR4 operating system; This figure is similar to Figure 3.9b, with the two UNIX sleeping states corresponding to the two blocked states. Point out that: UNIX employs two Running states to indicate whether the process is executing in user mode or kernel mode. Two states are essentially the same: (Ready to Run, in Memory) and (Pre-empted) as indicated by the dotted line. The distinction is made to emphasize the way in which the pre-empted state is entered. When a process is running in kernel mode (as a result of a supervisor call, clock interrupt, or I/O interrupt), there will come a time when the kernel has completed its work and is ready to return control to the user program. At this point, the kernel may decide to pre-empt the current process in favour of one that is ready and of higher priority. In that case, the current process moves to the pre-empted state. However, for purposes of dispatching, those processes in the pre-empted state and those in the Ready to Run, in Memory state form one queue.
74
UNIX Process States
75
A Unix Process A process in UNIX is a set of data structures that provide the OS with all of the information necessary to manage and dispatch processes. See Table 3.10 which organizes the elements into three parts: user-level context, register context, and system-level context.
76
Process Creation Process creation is by means of the kernel system call,fork( ). This causes the OS, in Kernel Mode, to: Allocate a slot in the process table for the new process. Assign a unique process ID to the child process. Copy of process image of the parent, with the exception of any shared memory. Increment the counters for any files owned by the parent, to reflect that an additional process now also owns those files. Assign the child process to the Ready to Run state. Returns the ID number of the child to the parent process, and a 0 value to the child process.
77
After Creation After creating the process the Kernel can do one of the following, as part of the dispatcher routine: Stay in the parent process. Transfer control to the child process Transfer control to another process. When the kernel has completed these functions it can do one of the following, as part of the dispatcher routine: • Stay in the parent process. Control returns to user mode at the point of the fork call of the parent. • Transfer control to the child process. The child process begins executing at the same point in the code as the parent, namely at the return from the fork call. • Transfer control to another process. Both parent and child are left in the Ready to Run state.
Similar presentations