정리 노트

프로세스(Process) 본문

개념 정리/운영체제

프로세스(Process)

꿈만 꾸는 학부생 2023. 7. 15. 21:19
728x90

이 포스트는 국민대학교 소프트웨어학부 '운영체제' 강의를 듣고 요약하는 포스트입니다. 원하시는 정보가 없을 수도 있습니다. 이 점 유의 바랍니다. 오류 지적은 매우 환영합니다!


프로세스의 정의

프로세스는 쉽게 말해 실행되고 있는 프로그램입니다.

출처: https://pages.cs.wisc.edu/~remzi/OSTEP/cpu-intro.pdf, 1페이지
The definition of a process, informally, is quite simple: it is a running program.

예를 들어 지금 이 블로그를 보고 있는 인터넷 브라우저도 프로세스, 게임도 프로세스, 음악을 재생하고 있는 프로그램도 프로세스입니다.

저희는 여러 프로그램들을 동시에 켜놓고 컴퓨터를 하고 있을 때가 많습니다. 블로그 글을 보며 음악을 들을 수도 있습니다. 이는 동시에 진행되기 때문에 사용자는 두 프로세스가 동시에 진행되고 있다고 생각합니다. 하지만 단일 CPU(단일 코어)인 컴퓨터라면 실질적으로 두 개 이상의 프로세스를 동시에 실행할 수 없습니다.

가능하게끔 보이는 이유는 운영체제가 CPU를 가상화해서 마치 CPU가 여러 개 있는 듯한 착각이 들게 하기 때문입니다

실제로는 하나의 프로세스씩 번갈아 가며 실행하고 있습니다. 이러한 기술을 time sharing이라 알려져 있습니다.

출처: https://pages.cs.wisc.edu/~remzi/OSTEP/cpu-intro.pdf, 1페이지
The OS creates this illusion by virtualizing the CPU. 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). his basic technique, known as time sharing of the CPU, (후략)

프로세스의 생성

운영 체제가 프로그램을 동작시키기 위해 먼저 하는 것은 프로그램의 코드와 정적 데이터(ex. 초기화된 변수들)를 메모리(프로세스의 address space)로 올리는 것입니다.

출처: https://pages.cs.wisc.edu/~remzi/OSTEP/cpu-intro.pdf, 4페이지
The first thing that the OS must do to run a program is to load its code and any static data (e.g., initialized variables) into memory, into the ad- dress space of the process.

처음에 프로그램은 실행 가능한 형태로 저장 장치에 저장되어 있습니다. 따라서 프로그램을 로딩하는 프로세스는 운영 체제가 저장된 프로그램의 byte들을 읽어서 메모리로 올리는 기능을 가지고 있어야 합니다.

출처: https://pages.cs.wisc.edu/~remzi/OSTEP/cpu-intro.pdf, 4페이지
(전략); 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.

로딩의 과정이 끝나면, 프로세스의 메모리의 일부는 프로세스의 run-time stack(또는 stack), heap에 할당합니다. 그리고, 프로세스와 관련이 있는 입출력에 대한 초기화 작업을 진행합니다. Unix 시스템으로 예를 들면, 각 프로세스는 기본적으로 3개의 열린 file descriptors(리눅스 혹은 유닉스 계열의 시스템에서 프로세스가 파일을 다룰 때 사용하는 개념, 프로세스에서 특정 파일에 접근할 때 사용하는 추상적인 값)를 가지고 있습니다. 이 세 가지는 각각 표준 입력, 표준 출력 그리고 에러입니다.

출처: https://pages.cs.wisc.edu/~remzi/OSTEP/cpu-intro.pdf, 4페이지
Once the code and static data are loaded into memory, there are a few other things the OS needs to do before running the process. Some memory must be allocated for the program’s run-time stack (or just stack).
(중략)
The OS may also allocate some memory for the program’s heap.
(중략)
The OS will also do some other initialization tasks, particularly as related to input/output (I/O). For example, in UNIX systems, each process by default has three open file descriptors, for standard input, output, and error;

이러한 준비 작업들이 모두 끝나고, 운영 체제는 CPU가 새로 생성된 프로세스의 main() 함수 작업을 시행하도록 전환합니다. 이렇게 프로세스는 실행이 됩니다.

출처: https://pages.cs.wisc.edu/~remzi/OSTEP/cpu-intro.pdf, 4페이지
(전략): to start the program running at the entry point, namely main(). By jumping to the main() routine (through a specialized mechanism that we will discuss next chapter), the OS transfers control of the CPU to the newly-created process, and thus the program begins its execution.

프로세스의 상태

프로세스의 상태는 간단하게 3가지로 표현할 수 있습니다.

  • Running: 프로세스가 실행되고 있는 상태를 의미합니다.
  • Ready: 프로세스가 실행될 준비는 되었지만 어떠한 이유로 운영 체제가 이 프로세스에게 CPU 자원을 주지 않은 상태(실행 중이 아닌 상태)를 의미합니다.
  • Blocked: 어떠한 작업이 끝날 때까지 기다려야 해서 프로세스가 실행될 준비가 되지 않는 상태를 의미합니다.(ex. 프로세스의 I/O 요청 -> I/O 작업이 끝날 때까지 기다려야 한다.) 이 상태일 때는 다른 프로세스를 실행할 수 있다.

source: https://pages.cs.wisc.edu/~remzi/OSTEP/cpu-intro.pdf, 6페이지
source: https://pages.cs.wisc.edu/~remzi/OSTEP/cpu-intro.pdf, 7페이지

참고 자료

File Descriptor란: https://twofootdog.tistory.com/51

 

파일 디스크립터(File Descriptor) 란 무엇인가?

1. 개념 파일 디스크립터(File Descriptor)란 리눅스 혹은 유닉스 계열의 시스템에서 프로세스(process)가 파일(file)을 다룰 때 사용하는 개념으로, 프로세스에서 특정 파일에 접근할 때 사용하는 추상

twofootdog.tistory.com

 

728x90