728x90

Process: running program
Program :

  • itself is a lifeless thing.
  • Just sits there on the disk.
  • a bunch of instructions and maybe some static data

*con-text switch
to stop running one program and start running another

*scheduling policy
are algorithms for making some kind of decision within the OS.


How To Provide The Illusion Of Many CPUS?

⇒ Virtualizing.

By running one process, then stopping it and running another, and so forth, the OS can promote the illusion that many virtual CPUs exist when in fact there is only one physical CPU (or a few).


Basic technique: time-sharing → Process ↑ Performance ↓
To implement virtualization of CPU =
low-level machinery(mechanism) + high-level intelligence(policy)

Process


To understand what constitutes a process → We thus have to understand its machine state:
What a Program can read or update when it running.
At any given time, what parts of machine state are important to the execution of these programs?

machine state → Memory, Register

Memory(address space)

Instructions lie in Memory. the data that the running program reads and writes sits memory.

Register

many instructions explicitly read or update registers and thus clearly they are important to the execution of the process.

  • Program Counter : PC = Instruction Pointer : IP
  • Stack Pointer
  • frame Pointer

PC or IP tells which instruction of the program is currently being executed.

used to manage the stack for function parameters, local variables, and return address

*Persistent storage ← Program often access

Such I/O information might include a list of the files the process currently has open

Process Control Block → PCB


프로세스에 대한 정보를 저장하는 자료구조
운영체제는 프로세스를 PCB 단위로 관리하며 프로세스 스케줄링을 위한 정보를 PCB를 통해 관리한다.
프로세스가 생성될 때마다 고유의 PCB가 생성되며, 프로세스가 완료되면 PCB는 제거된다.
프로세스 간 Switching이 발생할 때, 운영체제는 PCB를 이용해서 상태를 전이시킨다.
(State Transition)

PCB의 데이터 구성

  • Process Identification Data
  • Process State Data
  • Process Control Data

PCB는 다음 정보를 가지고 있다.

  1. Process ID: 프로세스를 구분하는 ID
  2. Process State: 각 State들의 상태를 저장한다.
  3. Program Counter: 다음 Instruction의 주소를 저장하는 카운터, CPU는 이 값을 통해 Process의 Instruction을 수행한다.
  4. Register: Accumulator, CPU Register, General Register등을 포함한다.
  5. CPU Scheduling Information: 우선 순위, 최종 실행시간, CPU 점유시간 등이 포함된다.
  6. Memory Information: 해당 프로세스 주소 공간(lower bound~upper bound)정브를 저장.
  7. Process Information(페이지 테이블, 스케줄링 큐 포인터, 소유자, 부모 등)
  8. Device I/O Status(프로세스에 할당된 입출력 장치 목록, 열린 팔린 목록 등)
  9. Pointer: 부모/자식 프로세스에 대한 포인터, 자원에 대한 포인터 등
  10. Open File List: 프로세스를 위해 열려있는 파일의 리스트

Process Application Programing Interface → Process API

some idea of what must be include in any interface of an OS.

  • Create

An operating system must include some method to create new process.

▲ type a command into the shell.
▲ double-click on an application icon.

  • Destroy

many processes will run and just exit by themselves when complete they don't, however,
the user may wish to kill them, and thus an interface to halt a runaway process is quite useful.

  • Wait

Sometimes it is useful to wait for a process to stop running thus some kind of wating interface is often provided.

  • Miscellaneous Control

Other than killing or waiting for a process, there are sometimes other control that are possible.
ex) 1. to suspend a process. 2. stop it from running for a while

  • Status ← such as how long it has run for, or what state it is in.

There are usually interfaces to get some status information about a process.


메모리 구조 이해하기

Stack에는 함수, 지역변수
Heap은 동적으로 변경되는 Heap같은 것들
BSS 아직 초기화가 이루어지지 않은 변수
Data는 초기화가 된 변수
Code는 Code


Process Creation: A Little More Detail

Q. One mystery that we should unmask a bit is how programs are transformed into processes.

⇒⇒ Specifically, how does the OS get a program up and running?

The OS must do to run a program is to load its code and any static data into Memory.

Programs initially reside on disk (modern systems, flash-based SSD) in some kind of executable format.
▪ thus, the process of loading a program and static data into memory requires the OS to read those bytes from disk and place them in memory somewhere By loading places of code or data only as they are needed during program execution.

To truly understand how lazy loading of pieces of code and data works you'll have to understand more about the machinery of Paging and Swapping

For now, just Remember that before running anything, the OS clearly must do some work to get the important program bits from disk into memory


Once the code and static data are loaded into memory → there are a few other the OS needs to do before running the process.

  1. Some memory must be allocated for the program's run-time stack (or just stack).
  2. C programs use the stack for local variables, function parameters, and return address.
  3. The OS allocates this memory and gives it to the process.
  4. The OS will also likely initialize the stack with arguments. specifically, it will fill in the parameters to the main() function, i.e., argc and argv array.

The OS may also allocate some memory for the program's heap.

In C programs, the heap is used for explicitly requested dynamically-allocated data; programs request such space by calling malloc() and free it explicitly by calling free().

The heap is needed for data structures such as linked lists, hash tables, trees, and other interesting data structures. The heap will be small at first;
as the program runs, and requests more memory via the malloc() library API, the OS may get involved and allocate more memory to the process to help satisfy such calls.


The OS will also do some other initialization tasks, particularly as related to input/output(I/O).


By loading the code and static data into memory → by creating and initializing a stack → by doing other work as related to I/O setup → the has now (finally) set the stage for program execution. → to start the program running at the entry point( main() ) ⇒ By jumping to the main() routine, the OS transfers control of the CPU to the newly-create process → the program begins its execution.


Process States

  • Running

In the running state, a process is running on a processor. → it is executing instructions.

  • Ready

In the ready state, a process is ready to run but for some reason the Os has chosen not to run it at this given moment.

  • Blocked

In the blocked state, a process has performed some kind of operation that makes it not ready to run until some other event takes place. common ex)When a process initiates an I/O request to a disk, it becomes blocked and thus some other process can use the processor.


Structure

Process List: Process Status를 파악하기 위한 자료구조

Register Context: Process가 중단되었을 때 해당 프로세스의 레지스터 값들을 저장하는 자료구조


👀아이콘 제작자 Eucalyp

Eucalyp 디자인의 무료 벡터 아이콘

반응형

+ Recent posts