류짱:Beyond MySelf

프로세스와 스레드의 개념 본문

Microsoft/Windows Platform

프로세스와 스레드의 개념

リュちゃん 2010. 8. 26. 10:40

프로세스(Process)
프로세스란 실행 중인 프로그램을 나타내는 말로서 디스크에 저장 되어 있는 프로그램이 실행 되면 그 프로그램은 자신의 고유한 메모리 공간에 프로그램의 코드가 읽혀질 것이고 CPU는 메모리에 로드된 프로그램의 명령어를 하나하나 읽어서 실행 할 것이다. 그리고 이렇게 실행 중인 상태의 프로그램을 프로세스(process)혹은 태스크(Task)라 부른다.

프로세스가 가지는 특성은
?
자원의 소유단위: 각각의 프로세스는 자신의 실행 이미지 로드와 실행에 필요한 추가적인 메모리 공간을 가지고 있어야 할 것이며 이들은 각 프로세스마다 구별되어야 할 것이고 해당 프로세스가 접근 하고자 하는 파일, I/O 장치들에 대해서 또한 프로세스 단위로 할당 받아 관리 되어야 함.

디스패칭 단위: 프로세스는 하나의 프로그램이 운영체제로부터 CPU의 자원을 일정 기간 동안 할당 받아 명령어를 실행 하는 것이며 운영체제는 여러 개의 프로세스가 병렬적으로 실행 되게 하기 위해서 CPU의 사용 시간을 각각의 프로세스에 골고루 나눠주어야 한다.

Windows
같은 운영체제는 보다 효율적인 멀티태스킹을 위하여 하나의 프로세스에서 여러 개의 디스패칭 단위가 실행 될 수 있도록 하고있으며, 이러한 디스패칭 단위를 스레드(Thread)라 부른다.

스레드(Thread)
스레드란 실제적으로 명령어가 CPU를 사용하여 실행 되어지는 객체 단위이며 Windows에서는 하나의 프로세스가 여러 개의 스레드를 실행 할 수있도록 한다. 또한 같은 프로세스에 있는 스레드는 자원과 상태를 공유하게 된다.

Windows Architecture - The Basics
http://blogs.technet.com/b/askperf/archive/2007/04/10/windows-architecture-the-basics.aspx

Think of a process as a room and a thread as a person in the room.  A program is a set of instructions for the person in the room to carry out.  Looking at it in this fashion, it is easy to see that the process itself doesn't do any work, but the thread does.  A thread lives in a process, and executes the instructions of the program.
 
With that analogy in mind, a Windows process includes the following:
1. An executable program, consisting of initial code and data
2. A private virtual address space
3. System resources that are accessible to all threads in the process
4. A unique identifier, called a process ID
5. At least one thread of execution
6. A security context (also known as an access token)
 
The thread is what Windows schedules for execution within a process.  Without threads, the program used by the process cannot run.  Threads consist of the following components:
1. The contents of the registers representing the state of the processor
2. Two stacks - one for the thread to use when executing kernel-mode instructions, and one for user-mode
3. A private storage area used by the subsystems, run-time libraries and DLL's
4. A unique identifier, called a thread ID



[
참고 자료]

Windows
구조와 원리(OS를 관통하는 프로그래밍의 원리)
정덕영 저

Windows Architecture - The Basics
http://blogs.technet.com/b/askperf/archive/2007/04/10/windows-architecture-the-basics.aspx