상세 컨텐츠

본문 제목

[운영체제] 2. Process

CS구멍/운영체제🐣

by :Eundms 2021. 3. 17. 09:45

본문

 

컴파일러 Source Code -> Object 파일
링커 여러 Object 파일들과 라이브러리를 연결하여, 메모리로 로드 될 수있는 하나의 Executable로 변환.
로더 Executable을 실제 메모리에 올려주는 역할을 담당하는 운영 체제의 일부.

Object 파일 

프로세스로 변환되기 위한 정보가 삽입되어 있음.

Relocatable Address로 표현됨.

 

Executable

특정한 환경 (OS)에서 수행될 수 있는 파일.

프로세스로의 변환을 위한 header, 작업 내용인 text, 필요한 데이터인 Data를 포함.

Absolute Address로 표현됨.

=> 결과물이 수행될 OS와 CPU에 따라 다른 형태의 파일을 만듦.

 

메모리에 올리는 과정

  1. Executable header를 읽어 text와 data의 크기를 결정.
  2. 프로그램을 위한 Address Space생성
  3. 실행명령어Data들을 executable로부터 생성한 Address Space 복사
  4. 프로그램Argument들을 stack으로 복사
  5. CPU내 Register를 초기화하고, start-up routine으로 jump

프로세스 메모리에 올리기

Runtime System

프로그램과 연결하여 상호작용함.

ex) C파일 컴파일 및 실행과정

  1. GCC는 start-up code object 파일을 추가하여 프로그램을 컴파일하며, 이때 기본라이브러리들도 동적으로 링크됨.
  2. Process를 시작하기 위해 커널은 프로그램카운터를 _start함수의 주소로 지정.
  3. _start함수는 동적으로 링크된 c라이브러리 및 쓰레드 환경을 초기화 하기 위해 __libc_start_main 함수 호출
  4. 라이브러리 초기화를 진행한 이후, 프로그램의 main 함수가 호출된다.

Process

프로세스를 어떠한 기준으로 설계해야 하며, 어떤 것이 필요한가?!

Abstraction for
Execution Unit (스케줄링의 단위)
Protection Domain (서로 침범하지 못함)

Implemented with
Program Counter
Stack
Data Section

(디스크에 저장된 프로그램으로부터 변환되어 메모리로 로딩된 것 - 프로세스)

Process State

New : The process is being created

Running: Instructions are being executed

Waiting: The process is waiting for some event to occur (an I/O completion or reception of a signal)

Ready: The process is waiting to be assigned to a processor.

Terminated: The process has finished execution.

 

커널 내에 ready queue, waiting queue, running queue를 두고 프로세스들을 상태에 따라 관리한다.

process state

 

Process Control Block

PCB 구조

Context Switch

cpu slices 방식으로 인해 나타나는 현상

CPU switches to a new process, Kernel must save the state of the old process and load the saved states for the new process.

 

Context switching time is overhead. CPU time slices를 할당할 수 없음. 

Context switching time의 경우, 

process management의 scheduling 방식에 따라, 

hardware가 지원하는 기능, 방식에 따라 차이가 있을 수 있음.

프로세서 구조에 따라 다르다.

 

OSProcess CreationProcess Termination을 제공한다.

Process Creation

The processes in the system can execute concurrently, and they must be created and terminated dynamically.

// 운영체제 마다 다름.

- parent process vs. child process

: resource sharing 방식과 execution 방식이 운영체제마다 다르다.

예를 들어, Parent가 Child를 안 기다리고 독립적으로 수행될 수 있는 경우, 자원을 공유하지 않는 게 좋다.

Parent에 종속적으로 child가 생성되는 경우는 때때로 parent의 자원을 공유할 필요가 있다.

 

Process Termination

# 정상적으로 끝나는 경우, OS는 exit system call을 통해 프로그램을 메모리로부터 삭제

A process terminates when it finishes executing its final statement and asks the Operating System to delete it by using exit system call.

# return을 통해 나온 output data가 wait을 통해 parent로 전달됨.

  • Output data from child to parent (via wait)
  • Process’s resources are deallocated by OS

 

# 정말 error에 의해 abnormal하게 프로세스가 종료되는 경우.

The abort function causes abnormal process termination to occur.

  • The SIGABRT signal is sent to the calling process.
  • Core dump is made.

 

Cooperating Process

Independent process cannot affect or be affected by the execution of another process.

원래는 다른 process에 의해 관여되면 안되었지만, 서로 다른 프로세스들이 협력해야하는 경우

interprocess communication을 통해 안전하게 공유된 것에 접근할 수 있도록 한다.

 

'CS구멍 > 운영체제🐣' 카테고리의 다른 글

[운영체제] 8. 스레드  (0) 2021.03.23

관련글 더보기

댓글 영역