多任务处理是在一段时间内同时执行多个任务或进程的方法。抢占式和协作式多任务是两种类型的多任务。
在抢占式多任务中,操作系统可以发起从正在运行的进程到另一个进程的上下文切换。换句话说,操作系统允许停止当前正在运行的进程的执行并将 CPU 分配给某个其他进程。操作系统使用一些标准来决定一个进程在允许另一个进程使用操作系统之前应该执行多长时间。从一个进程控制操作系统并将其交给另一个进程的机制称为抢占或抢占。
在协作多任务中,操作系统从不启动从正在运行的进程到另一个进程的上下文切换。上下文切换仅在进程自愿定期让出控制权或空闲或逻辑阻塞以允许多个应用程序同时执行时发生。此外,在这种多任务处理中,所有进程都为调度方案协同工作。
让我们看看抢占式多任务和协作式多任务之间的区别。
SR.NO. | Preemptive Multitasking | Cooperative Multitasking |
---|---|---|
1 | Preemptive multitasking is a task used by the OS to decide for how long a task should be executed before allowing another task to use the OS. | Cooperative multitasking is a type of computer multitasking in which the operating system never initiates a context switch from a running process to another process. |
2 | It interrupts applications and gives control to other processes outside the application’s control. | In cooperative multitasking, process scheduler never interrupts a process unexpectedly. |
3 | The operating system can initiate context switch from a running process to another process. | The operating system does not initiate a context switch from a running process to another process. |
4 | A malicious program initiates an infinite loop, it only hurts itself without affecting other programs or threads. | A malicious program can bring the entire system to a halt by busy waiting or running an infinite loop and not giving up control. |
5 | Preemptive multitasking forces applications to share the CPU whether they want to or not. | In cooperative multitasking, all programs must cooperate for it to work. If one program does not cooperate, it can hog the CPU. |
6 | UNIX, Windows 95, Windows NT operating systems are examples of preemptive multitasking . | Macintosh OS version 8.0-9.2.2 and Windows 3.x operating systems are examples of cooperative multitasking. |