进程(Process)和线程(Thread)有什么区别和联系?

进程(Process)和线程(Thread)有什么区别和联系?

进程和线程都是独立的一组执行序列。
thread使用共享内存,process是独立的内存。
Both processes and threads are independent sequences of execution. The typical difference is that threads (of the same process) run in a shared memory space, while processes run in separate memory spaces.

Process
Each process provides the resources needed to execute a program. A process has a virtual address space, executable code, open handles to system objects, a security context, a unique process identifier, environment variables, a priority class, minimum and maximum working set sizes, and at least one thread of execution. Each process is started with a single thread, often called the primary thread, but can create additional threads from any of its threads.

Thread
A thread is the entity within a process that can be scheduled for execution. All threads of a process share its virtual address space and system resources. In addition, each thread maintains exception handlers, a scheduling priority, thread local storage, a unique thread identifier, and a set of structures the system will use to save the thread context until it is scheduled. The thread context includes the thread’s set of machine registers, the kernel stack, a thread environment block, and a user stack in the address space of the thread’s process. Threads can also have their own security context, which can be used for impersonating clients.

Definition定义
————-
Process
进程是应用程序的一次运行活动;
从操作系统核 心角度来说,进程是操作系统分配和调度系统内存资源、cpu时间片等资源的基本单位,为正在运行的应用程序提供运行环境。

Thread
线程是程序内部有并发性的顺序代码流。是cpu调度资源的最小单元。

Units单位大小
————
Process
进程是操作系统分配和调度系统内存资源、cpu时间片 等资源的基本单位;一个进程至少包括一个线程。
进程是操作系统资源管理的实体。
Thread
线程是cpu调度资源的最小单元。
线 程是进程的实体。

Resource系统资源分配上
————-
Process
每个进程都有自己的内存地址空间。
Thread
线 程没有自己独立的内存资源,它只有自己的执行堆栈和局部变量。但是在同属一个进程的多个线程中他们可以共享进程的内存

资源。

Running执行过程中
————-
执行过程中,进程有内存单元的初始入口点,在存活阶段里拥有独立的地址空间。
A process has the initial entrance of Memory Units and room of address.

进程是应用程序的一次运行活动,独立地执行;所以某一个进程崩溃以后,在保护模式下不会影响其他的进程,
健壮性好。
A process is activity of application.

父进程与子进程 的关系待研究深入中……

每个已创建的进程都可以创建进程,创建进程的进程称为父进程,被创建的新进程为子进程,这样便形成一个进程树。父进程与子进程可并行执行;父进程等待子进程终止执行。父进程终止后,所有的子进程也都必须要终止。

Thread
而线程不能独立地执行,它必须依附在一个运行中的应用程序上。
但是,同一个进程中的多个线程可以并发地执行,并发性 高,系统在数据交换上花费的资源少,运行效率高。

主线程与其他线程 的关系待研究深入中……

每个进程里都会有一个主线程,由它创建其他线程。

======================================================

Common ground 共同点
————–
Process和Thread都有生命周期:
create 创建,ready就绪,running运行,waitSleepJoin阻塞,suspend挂起,stoped死亡

发表评论

您的电子邮箱地址不会被公开。