사용자:苦笑/작업장2

위키백과, 우리 모두의 백과사전.

전산학 분야에서 멀티태스킹은 다수의 태스크(혹은 프로세스)가 중앙처리장치(이하 CPU)와 같은 공용 자원을 나누어 사용하는 것을 말한다. 엄밀히 말해 한 개의 CPU를 가진 개인용 컴퓨터는 특정 순간에 수행되는 태스크의 갯수가 하나뿐이다. 멀티태스킹은 스케쥴링이라는 방식을 사용하여 컴퓨터사용자에게 병렬컴퓨팅이 이루어진 것과 같은 환경을 제공한다. 스케쥴링 방식은 CPU의 시간을 일정한 기준에 따라 나누어 각 태스크가 사용할 수 있도록 분배 한다. 태스크가 분배 받은 시간동안 CPU를 사용할 때 다른 태스크들은 자신의 차례가 오기를 기다린다. 분배 받은 시간이 종료되어 태스크가 사용하던 CPU를 다른 태스크가 사용할 수 있도록 재배정하는 것을 문맥교환이라 하는데 스케쥴링에서 이 문맥교환이 충분히 자주 발생하게 되면 컴퓨터 사용자는 병렬컴퓨팅이 이루어진 것처럼 느끼게 된다.

멀티캐스팅은 다수의 CPU를 내장한 컴퓨터(즉, 멀티프로세서)에서도 유효한데. 멀티태스킹을 사용하게되면 탑재한 CPU의 숫자보다 많은 수의 태스크를 동시에 수행 할 수 있게 된다.

운영체제는 아래의 일반적인 카테고리로 구분할 수 있는 다양한 방식의 스케쥴링을 지원한다.

  • 멀티프로그래밍 시스템에서 현재 실행되고 있는 태스크는 다른 외부 이벤트를 기다려야 하는 상황이 되거나, 컴퓨터의 스케쥴러가 강제로 실행중인 태스크를 중단시킬 때까지 계속 실행 된다. 멀티 프로그램 시스템은 CPU 사용율을 극대화할 수 있도록 설계 되었다.
  • 시분할 시스템에서 현재 실행되고 있는 태스크는 스스로 혹은 하드웨어 인터럽트 따위의 외부적인 이유로 중앙처리장치의 점유를 포기해야 한다. 시분할 시스템은 다수의 프로그램이 거의 동시에 수행 될 수 있도록 해준다. "시간을 분할한다"라는 표현은 단말에 위치한 사용자가 함께 공유할 수 있는 IBM사의 TSO, CP/CMS와 같은 컴퓨터를 가리키기위해 쓰였다.
  • 실시간 시스템, 몇 개의 대기중인 태스크들이 외부 이벤트가 발생하였을 때, CPU를 점유 받을 수 있도록 보장해준다. 실시간 시스템은 시간내에 처리가 되야 하는 산업 로봇과 같은 기계적인 장치를 제어 하기 위해 사용된다.

동일한 시스템을 여러명이 공유해서 쓰는 것을 나타내던 시분할 이라는 용어는 개인용 컴퓨터와 워크스테이션의 발전으로 멀티태스킹이라는 용어로 대체 되어 특수한 경우를 제외하고 현재는 거의 사용되지 않는다.

멀티프로그래밍[편집]

CPU에 비하여 주변장치들은 상대적으로 매우 느리다. 만약 컴퓨터가 주변장치에 접근해야 하는 프로그램을 실행시키면 CPU는 아무것도 하지 못하고, 주변장치가 데이터 처리를 완료해 줄 때까지 기다려야 했다. 전산학 발전 초기단계에서 CPU 시간은 매우 귀중한 자원이었기 때문에 이러한 CPU 시간의 낭비는 매우 비효율적으로 보였다.

이러한 낭비를 막기 위해서 1960년대가 되면서 최초의 멀티 프로그래밍 시스템을 개발하려는 움직임이 있었다. 이 시스템에서는 몇 개의 서로 다른 프로그램들이 컴퓨터의 메모리에 불러들여진다. 첫 번째 프로그램이 실행되다 주변장치의 처리를 기다려야 하게 되면, 이 프로그램의 문맥은 저장이 되고, 두 번째 프로그램이 실행될 기회를 얻게 된다. 이런식의 처리 과정이 모든 프로그램이 실행 될 때까지 반복적으로 일어난다.

멀티프로그래밍은 프로그램이 적절한 시간안에 완료되는 것을 보장해주지는 못한다. 사실, 아주 먼 옛날의 프로그램도 주변장치에 접근할 필요없이 몇시간이고 잘 동작하였다. 이러한 컴퓨터 환경은 활성화된 단말기 앞에 사용자가 결과를 확인하기 위해서 대기하고 있지만 않다면 특별한 문제가 없었다. 사용자는 단지 컴퓨터를 조작하는 사람에게 천공카드 한묶음(프로그램)을 건내주고 떠났다가, 몇시간 후 출력된 결과를 확인하기 위해서 다시 돌아오면 되기 때문이다. 멀티 프로그래밍은 여러개의 순차프로그램들이 처리될 때 대기시간을 크게 줄여주었다.

Cooperative multitasking/time-sharing[편집]

When computer usage evolved from batch mode to interactive mode, multiprogramming was no longer a suitable approach. Each user wanted to see his program running as if it was the only program in the computer. The use of time sharing made this possible, with the qualification that the computer would not seem as fast to any one user as it really would be if it were running only that user's program.

Early multitasking systems consisted of suites of related applications that voluntarily ceded time to each other. This approach, which was eventually supported by many computer operating systems, is today known as cooperative multitasking. Although it is now rarely used in larger systems, cooperative multitasking was once the scheduling scheme employed by Microsoft Windows (prior to Windows 95 and Windows NT) and Mac OS (prior to Mac OS X) in order to enable the running of multiple applications simultaneously. Windows 9x also used cooperative multitasking, but only for 16-bit legacy applications, much the same way as pre-Leopard PowerPC versions of Mac OS X used it for Classic applications. The network operation system NetWare used cooperative multitasking up to NetWare 6.5. Cooperative multitasking is still used today on RISC OS systems.

Because a cooperatively multitasked system relies on each process regularly giving up time to other processes on the system, one poorly designed program can consume all of the CPU time for itself or cause the whole system to hang. In a server environment, this is a hazard that makes the network brittle and fragile. All software must be evaluated and cleared for use in a test environment before being installed on the main server, or the entire network either slows down or comes to a halt when a program on the server misbehaves.

선점형 멀티태스킹/시분할[편집]

선점형 멀티태스킹은 컴퓨터시스템이 각각의 태스크를 처리하는 시간을 좀 더 일정한 크기의 "슬라이스"로 나누어서 처리하게 도와준다. 또한, 시스템이 좀더 중요한 외부사건 ( 예를 들어 즉시 처리되어야 하는 데이터가 입력되었다거나 )이 발생하였을때, 좀더 신속하게 대응할 수 있도록 해준다. Preemptive multitasking allows the computer system to more reliably guarantee each process a regular "slice" of operating time. It also allows the system to rapidly deal with important external events like incoming data, which might require the immediate attention of one or another process.

운영체제는 하드웨어 자원들과 프로세스들을 선점형으로 구동시키는데 이점을 가지도록 개발되었다. 예를 들어 선점형 멀티태스킹은 1969년 유닉스의 초창기 버전에 구현되어 있다. [1] 또한, 선점형 멀티태스킹이 유닉스와 리눅스,솔라리스, BSD같은 유닉스 계열 운영체제들의 표준이었다. Operating systems were developed to take advantage of these hardware capabilities and run multiple processes preemptively. For example, preemptive multitasking was implemented in the earliest version of Unix in 1969, and is standard in Unix and Unix-like operating systems, including Linux, Solaris and BSD with its derivatives.

어떠한 순간에 프로세스는 두개의 범주중 하나에 속하게 된다: 하나는 입력이나 출력을 기다리고 있는 것이고( "I/O 바운드" ) 다른 하나는 CPU를 사용하는 것이다. ("CPU 바운드"). 선점형 시스템에서 소프트웨어는 종종 디스크나 키보드 또는 네트워크로부터의 입력을 기다리는 "폴링" 또는 "비지웨이트" 상태이다. At any specific time, processes can be grouped into two categories: those that are waiting for input or output (called "I/O bound"), and those that are fully utilizing the CPU ("CPU bound"). In primitive systems, the software would often "poll", or "busywait" while waiting for requested input (such as disk, keyboard or network input). During this time, the system was not performing useful work. With the advent of interrupts and preemptive multitasking, I/O bound processes could be "blocked", or put on hold, pending the arrival of the necessary data, allowing other processes to utilize the CPU. As the arrival of the requested data would generate an interrupt, blocked processes could be guaranteed a timely return to execution.

The earliest preemptive multitasking OS available to home users was Sinclair QDOS on the Sinclair QL, released in 1984. The Commodore Amiga 1000 released in 1985 (demonstrated by Debbie Harry and Andy Warhol at its unveiling) made use of a preemptive multitasking kernel that performed the circus act without a net (MPU) while managing a coprocessor that could process 80 instructions per scan line — no other computer on the market could touch it at the time, which was the sole reason the NewTek Video Toaster was developed to make use of its features. Preemptive multitasking was later adopted on the Apple Macintosh by Mac OS 9.x [2] as an additional API, i.e. the application could be programmed to use the preemptive or cooperative model, and all legacy applications were multitasked cooperatively within a single process. Mac OS X, being a Unix-like system, uses preemptive multitasking for all native applications, although Classic applications are multitasked cooperatively in a Mac OS 9 environment that itself is running as an OS X process (and is subject to preemption like any other OS X process).

A similar model is used in Windows 9x and the Windows NT family, where native 32-bit applications are multitasked preemptively, and legacy 16-bit Windows 3.x programs are multitasked cooperatively within a single process, although in the NT family it is possible to force a 16-bit application to run as a separate preemptively multitasked process.[3] 64-bit editions of Windows, both for the x86-64 and Itanium architectures, no longer provide support for legacy 16-bit applications, and thus provide preemptive multitasking for all supported applications.

실시간[편집]

다중작업의 다른 목적은 여러개의 서로 연관되지 않은 외부 활동들이 하나의 프로세서에 의해서 처리되어야 할 가능성이 있는 실시간 컴퓨팅 시스템의 설계에 있다. In such systems a hierarchical interrupt system was coupled with process prioritization to ensure that key activities were given a greater share of available process time.

Multithreading[편집]

As multitasking greatly improved the throughput of computers, programmers started to implement applications as sets of cooperating processes (e.g. one process gathering input data, one process processing input data, one process writing out results on disk). This, however, required some tools to allow processes to efficiently exchange data.

Threads were born from the idea that the most efficient way for cooperating processes to exchange data would be to share their entire memory space. Thus, threads are basically processes that run in the same memory context. Threads are described as lightweight because switching between threads does not involve changing the memory context.

While threads are scheduled preemptively, some operating systems provide a variant to threads, named fibers, that are scheduled cooperatively. On operating systems that do not provide fibers, an application may implement its own fibers using repeated calls to worker functions. Fibers are even more lightweight than threads, and somewhat easier to program with, although they tend to lose some or all of the benefits of threads on machines with multiple processors.[출처 필요]

Some systems directly support multithreading in hardware.

메모리 보호[편집]

여러개의 프로그램들이 메모리에 불려져 있을 때, 잘못된 동작을 하는 프로그램은 ( 의도적이든 의도적이지 않든간에 ) 다른 프로그램이나 심지어는 운영체제가 사용하는 메모리 영역에 데이터를 덮어 씌울 가능성이 있다.

따라서 운영체제는 현재 동작하고 있는 프로그램들이 전근할 수 있는 메모리 영역에 제한두고 있다. 만약 어떠한 프로그램이 자신에게 할당된 영역 외에 다른 프로그램이 사용하고 있는 메모리에 접근하여 데이터를 덮어 씌우려하면 그렇게 하기전에 운영체제에 의해서 즉각 중단 된다.

또 다른 혁신적인 아이디어는 메모리 접근성에 차등을 두는 것이다. 낮은 등급을 가지고 있는 태스크는 특정한 종유의 메모리 접근에 대한 허가가 나지 않으며, 또한 특정한 명령어의 실행 역시 허가 되지 않도록 조정된다. 어떤 태스크가 권한 밖의 작업을 수행하려고 한다면, 권한이 높은 감시 프로그램이 자동으로 동작하여 그 태스크의 작업 수행을 허가 할 것인지 말 것인지를 결정한다. This created the possibility of virtualizing the entire system, including virtual peripheral devices. Such a simulation is called a virtual machine operating system. Early virtual machine systems did not have virtual memory, but both are common today.

Memory swapping[편집]

Use of a swap file or swap partition is a way for the operating system to provide more memory than is physically available by keeping portions of the primary memory in secondary storage. While multitasking and memory swapping are two completely unrelated techniques, they are very often used together, as swapping memory allows more tasks to be loaded at the same time. Typically, a multitasking system allows another process to run when the running process hits a point where it has to wait for some portion of memory to be reloaded from secondary storage.

Programming in a multitasking environment[편집]

Processes that are entirely independent are not much trouble to program. Most of the complexity in multitasking systems comes from the need to share computer resources between tasks and to synchronize the operation of co-operating tasks. Various concurrent computing techniques are used to avoid potential problems caused by multiple tasks attempting to access the same resource.

Bigger computer systems were sometimes built with a central processor(s) and some number of I/O processors, a kind of asymmetric multi-processing.

Over the years, multitasking systems have been refined. Modern operating systems generally include detailed mechanisms for prioritizing processes, while symmetric multiprocessing has introduced new complexities and capabilities.

Notes[편집]

See also[편집]

틀:Operating System 틀:Parallel computing ko:다중작업