multithreading 任务与过程,真的有什么区别吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2560939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:07:27  来源:igfitidea点击:

Task vs. process, is there really any difference?

multithreadingprocesscomputer-sciencedefinitiontask

提问by Jens Kohl

I'm studying for my final exams in my CS major on the subject distributed systems and operating systems.

我正在为我的 CS 专业的分布式系统和操作系统主题的期末考试而学习。

I'm in the need for a good definition for the terms task, process and threads. So far I'm confident that a process is the representation of running (or suspended, but initiated) program with its own memory, program counter, registers, stack, etc (process control block). Processes can run threads which share memory, so that communication via shared memory is possible in contrast to processes which have to communicate via IPC.

我需要对术语任务、进程和线程有一个很好的定义。到目前为止,我确信进程是运行(或挂起,但已启动)程序的表示,具有自己的内存、程序计数器、寄存器、堆栈等(进程控制块)。进程可以运行共享内存的线程,因此与必须通过 IPC 通信的进程相比,通过共享内存进行通信是可能的。

But what's the difference between tasks and process. I often read that they're interchangable and that the term task isn't used anymore. Is that really true?

但是任务和过程之间有什么区别。我经常读到它们是可以互换的,并且不再使用术语任务。真的是这样吗?

采纳答案by Chris O

Processes and threads are the mechanics, task is more conceptual. You can queue a chuck of work to run asynchronously, on windows with .NET for example, this gets run on a thread from the thread pool. With OpenMP, a task would be part of your for loop running on one core.

进程和线程是机制,任务是更概念化的。您可以将大量工作排队以异步运行,例如在带有 .NET 的 Windows 上,这将在线程池中的线程上运行。使用 OpenMP,任务将成为在一个内核上运行的 for 循环的一部分。

Minor related notes: on windows, there are also jobs, thread pools, and fibers for mechanics. Also, a process is nothing without at least one thread running.

次要的相关说明:在 Windows 上,还有用于机制的作业、线程池和纤程。此外,一个进程如果没有至少一个线程运行就什么都不是。

回答by Andras Vass

The term "task"is mostly used in the context of scheduling*, when it can refer to either a threador a *process***, that can be scheduled to run on a processor.
From the scheduler's point of view there might be little-to-no difference between a thread and a process - both represent a taskthat must be scheduled.

术语“任务”主要用于调度*的上下文中,当它可以指线程或*进程***时,可以调度在处理器上运行。
从调度程序的角度来看,线程和进程之间可能几乎没有区别 - 两者都代表必须调度的任务

Recently, the term "task"is gaining more-widespread usage, especially among .NET developers, thanks to e.g. the Task Parallel Library. Within it, tasks are units of work that can be scheduledto run on threads from a pool of worker threads.

最近,“任务”一词得到了更广泛的使用,尤其是在 .NET 开发人员中,这要归功于任务并行库。在其中,任务是可以安排工作线程池中的线程上运行的工作单元。

* e.g in kernel programming, esp. on Linux
** theoretically, you could make up your schedulable entities

*例如在内核编程中,尤其是。在 Linux
**理论上,你可以组成你的可调度实体

回答by RumbaGuy

I'm old-school. Strictly speaking, "processing" is work performed in memory that does not involve input/output operations. A "task" is a process that includes I/O operations. Accordingly, a multi-tasking system can run concurrent I/O streams, whereas a multi-processing system must task switch its I/O. PC's have only one mouse, keyboard, etcetera, so they are not multi-tasking systems to me. I consider a mainframe to be a multi-tasking system.

我是老派。严格来说,“处理”是在内存中执行的不涉及输入/输出操作的工作。“任务”是包含 I/O 操作的进程。因此,多任务系统可以运行并发 I/O 流,而多处理系统必须任务切换其 I/O。PC 只有一个鼠标、键盘等,所以对我来说它们不是多任务系统。我认为大型机是一个多任务系统。

Threading is a technique for switching processing context. Allows a physical processor to drive multiple processes. No direct relationship to tasks.

线程是一种切换处理上下文的技术。允许一个物理处理器驱动多个进程。与任务没有直接关系。

回答by Oddthinking

It depends on your context.

这取决于你的上下文。

In Ada, a task is a construct in the programming language to enable concurrency.

在 Ada 中,任务是编程语言中用于启用并发的构造。

It isn't specified what operating system construct should be used to implement it, but it allows shared-memory between tasks, so a thread would be a more natural implementation.

没有指定应该使用什么操作系统构造来实现它,但它允许任务之间共享内存,因此线程将是更自然的实现。

回答by schaechtele

I think it's dependant of the underlying operating system which term is used.

我认为这取决于使用哪个术语的底层操作系统。

You could also think of task as a running piece of code. Then a part of a thread or a part of a process could be a task.

您也可以将任务视为正在运行的一段代码。那么线程的一部分或进程的一部分可能是一个任务。

回答by Riya

Process Process is a naturally occurring or designed sequence of operations or events, possibly taking up time, space, expertise or other resource, which produces some outcome. A process may be identified by the changes it creates in the properties of one or more objects under its influence

过程 过程是自然发生或设计的一系列操作或事件,可能会占用时间、空间、专业知识或其他资源,从而产生某种结果。一个过程可以通过它在其影响下的一个或多个对象的属性中产生的变化来识别

Thread Threads are similar to processes, in that both represent a single sequence of instructions executed in parallel with other sequences, either by time slicing or multiprocessing. Threads are a way for a program to split itself into two or more simultaneously running tasks

线程 线程类似于进程,因为两者都表示与其他序列并行执行的单个指令序列,通过时间切片或多处理。线程是程序将自身拆分为两个或多个同时运行的任务的一种方式

Task a set of program instructions is loaded in memory

Task 一组程序指令被加载到内存中