Linux Multi-task programming (i) tasks, processes, threads

Source: Internet
Author: User
Tags definition execution resource thread

Multi-task Introduction under Linux

First of all, a simple introduction to what is called multitasking system? What are tasks, processes, threads, respectively? What is the difference between them? , so you can get a macro understanding of these three, and then for each careful explanation.

What is a multitasking system? Multi-task systems are those that can run multiple applications at the same time, each of which is called a task.

Task definition: A task is a logical concept, a task that is performed by a software, or a series of actions that collectively achieve a goal.

Process definition: A process is a dynamic execution process of a program with independent functions on a dataset, which is the smallest unit of resource allocation and scheduling for a system.

Thread definition: A thread is a stand-alone running route within a process, the smallest unit of processor scheduling, or a lightweight process.

Read the definition, a little dizzy, or to say the difference between them. ① usually a task is one execution of a program, one task contains one or more subtasks that complete the independent function, and this independent subtask is a process or thread. ② a process can have multiple threads, each thread must have a parent process.

Task

A task is a logical concept, a task that is performed by a software, or a series of actions that collectively achieve a goal. Usually a task is one execution of a program, one task contains one or more subtasks that complete the independent function, and this independent subtask is a process or thread. For example, an anti-virus software operation is a task, the purpose is to protect the computer system from various viruses, this task contains a number of independent functions of the subtasks (process or thread), including real-time monitoring functions, timed killing function, firewall functions and user interaction functions. The relationship between tasks, processes, and threads is shown in Figure 1

Process

Basic concepts of the process

A process is a dynamic execution process of a program with independent functions on a dataset, which is the basic unit of resource allocation and scheduling for a system. The running of a task can activate multiple processes concurrently, and these processes work together to accomplish one of the ultimate goals of the task.

Processes have the characteristics of concurrency, dynamics, interactivity, independence, and Asynchrony.

Processes and procedures are fundamentally different: A program is a static piece of code, an ordered set of instructions stored in nonvolatile memory, without any concept of execution; a process is a dynamic concept that is the process of executing a program, including the whole process of dynamic creation, dispatch, and extinction, which is Minimum unit of program execution and resource management.

The process structure under Linux

Processes include not only program directives and data, but also all registers of program counters and processors and process stacks that store temporary data, so the process being executed includes all current activities of the processor.

Because Linux is a multitasking, multiple-process operating system, other processes must wait for the system to allocate the processor's right of use to itself before it can run. When a running process waits for other system resources, the Linux kernel will take control of the processor and assign the processor to other waiting processes, and he decides which process to allocate the processor to, according to the scheduling algorithm in the kernel, which means the kernel does not leave the processor idle.

The kernel stores all processes in a two-way circular chain list (the process list), where the header of the list is the Init_task descriptor. Each item in a list is a structure of type task_struct, called a process descriptor, that contains all the information related to a process, defined in the <include/linux/sched.h> file. TASK_STRUCT kernel structure is relatively large, it can fully describe a process, such as the status of the process, the process of the basic information, process identifiers, memory-related information, the parent process-related information, the process-related terminal information, the current working directory, open file information, received signal information.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.