(iii) process

Source: Internet
Author: User
Tags mutex

I. Concept of the process
A process is an instance of program execution. The operating system allocates system resources in process units, and processes are the smallest units of resource allocation.

Four elements of the Linux process

1: A program that is executed by a process that can be executed by multiple processes.2: Stand-alone kernel stack.3: Process Control Fast (task_struct: With this data structure, the process can become a basic unit of kernel scheduling to accept the kernel scheduling. At the same time, the structure also records the resources occupied by the process.4: Separate storage space: that is, with proprietary user space, in addition to the previous kernel space and user space.

Second, Process descriptor
1. The process descriptor contains all the information related to a process.
struct task_struct{
Process information
}

2. Process Descriptor Processing
For each process, the kernel allocates a separate memory area for it, which stores the kernel stack and a small process descriptor--thread_info structure corresponding to that process.
struct Thread_info {

}

Iii. Status of the process

Available for operation (task_running)

interruptible Wait (task_interruptble)

Non-disruptive Wait (task_uninterruptilbe)

Pause (task_stopped)

Tracking (task_traced)

Zombie (Task_zombie)

Zombie Undo (Exit_dead)

Thread
A thread exists in a process and is the smallest unit of operating system scheduling execution. In the popular point, the thread is the work.

Iv. Inter-process relations

Process 0 and Process 1 are created by the kernel, and Process 1 (init) is the ancestor of all other processes.

V. Process and wait queue
Wait queues (wait queue) are used to enable a process band to wait for a particular event to occur without frequent polling, the process sleeps within the wait time, and the kernel automatically wakes up when the waiting event occurs

1. Waiting for queue-related data structures
Each wait queue consists of two parts: the wait queue header (struct wait_queue_head_t) and the wait queue member (struct wait_queue).

  1. struct __wait_queue_head {
  2.      spinlock_t lock; /* because the wait queue can be modified at any time when the interrupt is interrupted, set a spin lock to ensure consistency */   
  3.      struct  list_ head task_list;  
  4. };   
  5. typedef struct  __wait_ queue_head wait_queue_head_t;  
  6.   
  7. struct  __wait_ queue {  
  8.      unsigned int  flags;   /* indicates whether the waiting process is a mutex or a non-mutex process */
  9.      struct  task_ struct *task;  /* task_struct*/
  10.      wait_queue_func_t func;  
  11.      struct  list_ head task_list;  
  12. };   
  13. typedef struct  __wait_ queue_head wait_queue_head_t  
2. The use of the wait queue is divided into the following two parts: (1) to make the current process sleep in a waiting queue, call wait_event (or an equivalent function), after which the process goes to sleep and gives control to the scheduler. In the case of block devices, when the kernel makes a request to a block device, because the data transfer does not occur immediately, the process sleep (2) corresponds to a process where the WAKE_UP function (or an equivalent function) must be called to wake the waiting queue for sleep.

V. Process creation

Fork Vfork

(iii) process

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.