본문 바로가기

프로그래밍/미분류

프로세스, 쓰레드, 잡 설명 (Windows Sysinternals Administrator’s Reference)

반응형

Windows® Sysinternals Administrator’s Reference

Mark Russinovich, Aaron Margosis


Part I Getting Started

 2 Windows Core Concepts


아래는 마크 러시노비치와 아론 마고시스의 <윈도우즈 시스인터널즈 관리자 레퍼런스>라는 책 영문판 Part I, 2장 중의 "프로세스, 쓰레드, 잡"이라는 절의 설명이다. 프로세스, 쓰레드, 잡의 개념에 대한 좋은 설명이라고 생각되어 번역하였다. 한국어 번역판이 아직 없는 것으로 알고 있어서, 정보공유의 차원에서 번역하여 블로그에 공개하였다. 저작권 상의 문제를 제기한다면 댓글 등으로 알려달라.


프로세스, 쓰레드, 잡


Processes, Threads, and Jobs



프로그램과 프로세스는 비슷한 것처럼 보이지만, 실은 이 둘 사이엔 본질적인 차이점이 있다.


Although programs and processes appear similar on the surface, they are fundamentally different.


프로그램은 정적인 명령의 시퀀스이고, 프로세스는 프로그램을 실행하기 위해 사용되는 일련의 자원의 담는 컨테이너이다. 가장 고차원의 추상화층에서 보면, 윈도우 프로세스는 다음으로 이루어진다.


A program is a static sequence of instructions, whereas a process is a container for a set of resources used to execute a program. At the highest level of abstraction, a Windows process comprises the following:


 * 프로세스 식별자(PID)라고 부르는 고유의 식별자 (숫자).

 * 하나 이상의 실행 쓰레드. 한 프로세스의 모든 쓰레드는 해당 프로세스 컨테이너가 가진 모든 자원에 접근할 수 있다.

 * 자기만의 가상주소공간. 이 가상 주소공간을 프로세스는 데이터와 코드를 저장하기 위해 사용한다.

 * 실행 프로그램. 이 실행 프로그램은 시작 코드와 데이터를 정의하며, 프로세스의 가상공간에 올라간다.

 * 다양한 시스템 자원을 가르키는 핸들의 리스트. 여기서 말하는 시스템 자원으로는 세마코어, 통신 포트, 파일 등이 있다.

 * 접근 토큰이라고 불리는 보안 컨텍스트. 사용자, 보안 그룹, 특권, UAC 가상화 상태, LSA 로그온 세션 식별자, 터미널 서비스 세션 식별자 등을 나타낸다.


■ A unique identifier called a process ID (PID).

■ At least one thread of execution. Every thread in a process has full access to all the resources referenced by the process container

■ A private virtual address space, which is a set of virtual memory addresses that the process can use to store and reference data and code

■ An executable program, which defines initial code and data and is mapped into the process’ virtual address space

■ A list of open handles to various system resources, such as semaphores, communication ports, and files

■ A security context called an access token that identifies the user, security groups, privileges, UAC virtualization state, LSA logon session ID, and terminal services session ID


이 외에 각 프로세스는 자신의 부모 프로세스의 PID기록도 가지고 있다. 그렇지만, 부모 프로세스가 종료하면 이 정보는 업데이트 되지 않는다. 따라서 이 PID는 없는 프로세스를 가르키거나, 또는 우연히 동일한 PID를 부여받은 전혀 엉뚱한 프로세스를 가르킬 수도 있다. 이 부모 프로세스의 PID는 정보적인 차원에서만 가지고 있는 것이다.


Each process also has a record of the PID of its parent process. However, if the parent exits, this information is not updated. Therefore, it is possible for a process to reference a nonexistent parent or even a different process that has been assigned the original parent’s PID. A process records its parent PID only for informational purposes, however.


윈도우는 또한 잡이라는 프로세스 모델의 확장형도 제공한다. 잡 개체의 주요 기능은 한 그룹의 프로세스를 관리하고 조작하기 쉬운 하나의 덩어리로 제공하는 것이다. 예를 들어, 잡을 이용하여 여러 개의 프로세스를 한꺼번에  죽일 수 있다. 이 때 각각의 프로세스가 무엇인지도 신경쓰지 않아도 된다. 


Windows provides an extension to the process model called a job. A job object’s main function is to allow groups of processes to be managed and manipulated as a unit. For example, a job can be used to terminate a group of processes all at once instead of one at a time and without the calling process having to know which processes are in the group.


잡 개체로 어떤 속성을 제어할 수도 있고, 잡과 연결되어 있는 프로세스들에 특정 제한을 가할 수도 있다. 예를 들어, 잡은 각 프로세스에 대한 또는 잡 전체에 대한 유저모드 실행 시간 제한, 또는 커밋 가망 메모리 제한도 가할 수 있다. WMI는 는 그 프로바이더들을 여러 호스트 프로세스에 로드하고, 이 프로세스들은 하나의 잡으로 제어하여 메모리 사용량과 WMI 프로바이더 호스트 프로세스의 총 수를 제한한다.


A job object also allows control of certain attributes and provides limits for the process or processes associated with the job. For example, jobs can enforce per-process or job-wide limits on user-mode execution time and committed virtual memory. Windows Management Instrumentation (WMI) loads its providers into separate host processes controlled by a job that limits memory consumption as well as the total number of WMI provider host processes that can run at one time.


이미 언급했듯이, 프로세스는 단순한 컨테이너일 뿐이다. 기술적으로 프로세스가 도는 게 아니다. 도는 건 쓰레드다. 쓰레드는 윈도우가 스케쥴링하여 수행하는 프로세스 내부의 개체이다. 쓰레드는 다음과 같은 컴포넌트로 구성된다.


As mentioned, a process is merely a container. Technically, it is not the process that runs—it is its threads. A thread is the entity within a process that Windows schedules for execution, and it includes the following essential components:


 * 프로세서의 상태를 나타내는 CPU 레지스터 집합의 값. 쓰레드가 다음에 수행해야 하는 기계어 명령을 가르키는 인스트럭션 포인터를 포함한다.

 * 커널모드에서 수행될 때 사용하는 커널 스택과 유저모드에서 수행될 때 사용하는 유저모드 스택

 * 서브시스템에서 사용하는 TLS라고 불리는 고유 저장소, 런타임 라이브러리, DLL

 * TID라고 불리는 쓰레드의 고유 식별자. 프로세스 ID와 쓰레드 ID는 같은 네임스페이스에서 생성되므로 이 둘이 겹치는 일은 없다.

 * 쓰레드는 때때로 자기만의 보안 컨텍스트를 갖는다. 클라이언트의 보안 컨텍스트를 임퍼스네이트하는 멀티쓰레드 서버 응용 프로그램에서 종종 쓰인다.


■ The contents of a set of CPU registers representing the state of the processor. These include an instruction pointer that identifies the next machine instruction the thread will execute.

■ Two stacks, one for the thread to use while executing in kernel mode and one for executing in user mode.

■ A private storage area called thread-local storage (TLS) for use by subsystems, run-time libraries, and dynamic-link libraries (DLLs).

■ A unique identifier called a thread ID (TID). Process IDs and thread IDs are generated from the same namespace, so they never overlap.

■ Threads sometimes have their own security context that is often used by multithreaded server applications that impersonate the security context of the clients they serve.


쓰레드가 자기만의 실행 컨텍스트를 가지지만, 한 프로세스 내의 쓰레드는 프로세스의 가상 주소공간 (과 프로세스가 소유한 기타 자원)을 공유한다. 따라서 한 프로세스 내의 모든 쓰레드는 다른 쓰레드의 메모리에 읽고 쓰기가 가능하다. 그러나, 쓰레드는 다른 프로세스의 주소 공간은 다른 프로세스가 공유 섹션으로 열어주어야 접근할 수 있다. (윈도우 API에서는 공유 섹션을 파일 매핑이라 부른다.) 또는 프로세스가 다른 프로세스의 메모리를 프로세스간 메모리 접근 함수를 이용할 권한이 있어야 한다.


Although threads have their own execution context, every thread within a process shares the process’ virtual address space (in addition to the rest of the resources belonging to the process), meaning that all the threads in a process can write to and read from one another’s memory. Threads cannot reference the address space of another process, however, unless the other process makes available part of its private address space as a shared memory section (called a file mapping object in the Windows API) or unless one process has the right to open another process to use cross-process memory functions.


기본적으로 쓰레드는 자기만의 접근 토큰을 갖지 않지만, 갖을 수도 있고, 각각의 쓰레드가 다른 보안 컨텍스트로 실행될 수 있다. 심지어 원격 윈도우의 보안 컨텍스트를 가질 수도 있다.


By default, threads don’t have their own access token, but they can obtain one, thus allowing individual threads to impersonate a different security context—including that of a process running on a remote Windows system—without affecting other threads in the process.

728x90