How is the process different from the flow?

Lecture



Today, I will explain in more detail about the thread, its differences from the process, and with the help of your miracle hands, you can create a console version of the Task Manager (such, a little poor and without a function, of course ... well, after all).

The first thing to learn is that the process consists of at least one stream . In the OS, each process corresponds to an address space and a single control flow. In fact, this determines the process.

On the one hand, the process can be viewed as a way of uniting related resources into one group . The process has an address space containing program text and data, as well as other resources. Resources are open files, child processes, unprocessed alarm messages, signal processing, accounting information, and more. It is much easier to manage resources by combining them in the form of a process.

On the other hand, the process can be viewed as a stream of executable cokomand or just a stream . The thread has a command counter that tracks the order in which actions are performed. It has registers in which current variables are stored. It has a stack containing a protocol for executing a process, where a separate frame is allocated for each procedure called but not yet returned. Although the flow must be executed within the process, the concepts of flow and process must be distinguished. Processes are used to group resources, and threads are objects that are alternately executed on the central processing unit.

The concept of threads adds to the process model the ability to simultaneously run several programs in the same process environment that are sufficiently independent. Multiple threads working in parallel in the same process are similar to several processes running in parallel on the same computer. In the first case, the threads share the address space, open files and other resources. In the second case, processes share physical memory, disks, printers, and other resources. Threads have some properties of processes, so they are sometimes called simplified processes. The term multithreading is also used to describe the use of multiple threads in a single process.

How is the process different from the flow?

Any stream consists of two components:

kernel object through which the operating system manages the thread. Statistical information about the thread is also stored there (additional threads are also created by the kernel);
A thread stack that contains the parameters of all functions and local variables that the thread needs to run the code.

To summarize, we fix: the main difference between processes and threads is that processes are isolated from each other, different address spaces are used in this way, and threads can use the same space (inside the process), performing actions without interfering with each other. to a friend. This is the convenience of multi-threaded programming : breaking the application into several consecutive threads, we can increase performance, simplify the user interface and achieve scalability (if your application is installed on a multiprocessor system, running threads on different processes, your program will work at a high speed =) ).

I decided not to talk about multi-threaded programming today, especially since there are excellent manuals on this topic (link below), but just to get acquainted with what tools CSharp has to interact with threads and processes. What to tell? Here's your source —http: //www.hotfile.ru/26806/ (password 123) (with comments), here's a screenshot for the seed - (PID - process id (integer), the stream has the same). So, MSDN is next to the Class1.cs window and go ... =)

How is the process different from the flow?

Understand the post without reading or for the lazy :

  1. A thread determines the sequence of code execution in a process.
  2. The process does not execute anything, it simply serves as a container of threads.
  3. Flows are always created in the context of a process, and their whole life passes only within its borders.
  4. Threads can execute the same code and manipulate the same data, as well as share kernel object handles, since the handle table is not created in separate threads, but in processes.
  5. Since threads consume significantly less resources than processes, try to solve your problems by using additional threads and avoid creating new processes (but approach this wisely).

Link to the topic : Basics of multi-threaded programming on CSharp: http://www.albahari.com/threading/index.html

And read more theory? Richter and Tanenbaum ...

PS (hymn to a newbie blogger): in fact, the song from the Gangster Petersburg series begins with the words: Blog and void, wordpress ... (familiar feelings?)

PSS (following the tracks of optimization): I understood here. In our century - the rapid development of the Internet and its penetration into all environments of life, God, began not only to give and take life, but also to follow PageRank, ban in forums and cheat hits on blogs :)


Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Operating Systems and System Programming

Terms: Operating Systems and System Programming