[Process] is an entity with resources, including:
1. A process has a virtual address space, different processes are different
In the virtual address space. If you want to communicate between processes, you must pass through the operating system.
Function call (IPC);
2. The process has other resources, such as open files and I / O devices. At the end of the process,
The operating system will automatically release all resources owned by the process. For example, if
Open is a file without close it, it will be automatically turned off after the process is over.
[Thread] is an entity of a set of specific instruction sequences. It can be arranged by operating system
Go to run (scheduling). On a single CPU system, it is clear that multiple threads are impossible.
Really run, can only run in a certain order. This order is
The scheduling algorithm of the operating system is determined.
Threads are status during their presence, for example:
Operation status: running;
READY Status: Waiting for the operating system to arrange it to run;
Blocking state: Waiting for a particular event, such as the I / O operation, etc .;
Sleep Status: Waiting for a timer timeout.
The thread only consumes the CPU time in the operating state. In other states, only
Requires management of schedulers.
Threads have their own CPU registers and stacks. When it occupies the CPU,
If the OS's scheduler decides' to drive, it will save the CPU register to
A data structure related to this thread; if the OS decides to make a thread
Run again, then the OS restores the CPU register from the data structure. This reach
The purpose of switching.
A process can contain multiple threads that share resources for the process.
[Example] Some operating systems, such as early UNIX, only in a process
There is a thread, or, it doesn't have a thread: the process is thread.
In this environment, users can link their own programs and some thread library.
To achieve multiple threads. But I don't know anything about the user thread, it still follows
The process is scheduled.
Some operating systems, such as Windows NT, OS itself can implement multithreading.
[Task] Some operating systems such as VxWorks, no process and thread concept,
Only tasks. The task is OS, which is approximately equivalent to the process. all
Tasks, including OS, unique address space in the shared system. All tasks sharing
All resources in the system. After a task opens a device, other tasks can
Read or write to this device.
However, it is still different. For example, threads in the process, they are open
The file descriptor will be recorded in the process control block (PCB) of the process, so
When the process terminates, the OS will turn off these files (if it is not closed).
However, in VxWorks, don't expect to turn off the file before the OS is turned off, so
There may be file data loss (if the task does not turn off the file).
In addition, standard input, standard output, and standard error These 3 devices are task specific,
That is, each task has its own three standard devices, not shared with other tasks.
Also, you can use vxVMI to implement task-based memory protection, for example, you can put a certain segment.
The memory logo is task A readable and written, task B read-only, and task C is completely unacceptable.
(A little similar to the process)
【area】
Unix has no thread, or the process and thread are 1: 1 relationship. Windows NT
The processes and threads are 1: M (a pair) relationship. Another one is M: M (multiple to more)
Relationship. Some operating systems such as TRIX and VXWORKS AE, with Domain's concept. One domain has an address space, but also a port (port; estimation is a shared memory),
Can communicate via ports. One domain can contain multiple threads / tasks, but tasks
Change your own domain.
【summary】
Processes in different operating systems, the characteristics of threads / tasks are different. by comparison
Or the rate can help us master.
for reference only.
Vxfree