Little talk Process: The basic concept of Linux process

Source: Internet
Author: User

1. Process Definition

Process is the core and foundation of operating system theory, and many concepts in operating system are related to process.

the definition of the process ,The process has a variety of definitions, and now lists some of the more famous.
The process is an independent and scheduled activity;
A process is an abstract entity that allocates and frees various resources when it executes a task;
A process is a unit of computation that can be executed in parallel;

A process is a running activity of a program with certain independent functions about a data set;


A process is a process of executing a program and is also the smallest unit of resource allocation.
Processes and procedures are fundamentally different:
The program is static, and it is an ordered set of instructions stored on disk, without any concept of execution;
And the process is a dynamic concept, it is the process of program execution, including the dynamic creation, scheduling and extinction of the whole process;
It is the smallest unit of program execution and resource management.


2. Process Classification

The Linux operating system consists of three different types of user processes, each of which has its own characteristics and attributes.
(1) Interactive process -a process initiated by the shell. The interactive process can be run either in the foreground or in the background.
(2) batch process -this process is not associated with a terminal, it is a sequence of processes that are submitted to a queue.
(3) Daemon -also known as the monitoring process, which is usually called the daemon process, is the background service process in Linux. It is a long-lived process, usually independent of the control terminal and periodically performs some sort of task or waits to handle certain occurrences. Daemons often start when the system boots, and terminate when the system shuts down.


3. Process Control block (PCB)
A Linux system describes a process through a process control block.
The Process Control block contains the status information of the process, control information, and resource information.
The process control block is the flag of the process, each process has a Process control block, Linux is represented by a data structure task_struct, and a pointer to each process control block is saved in the array task.
The TASK_STRUCT structure contains many fields, which can be divided into the following categories, depending on the function of the field:

Process Control block
(1) identification number. Each process has a process identification number (PID) and a parent process identification number (PPID), where the PID uniquely identifies a process. In addition, a process also has its own user identification number (UID) and group identification Number (GID), the system through these two identification numbers to determine the process of access to files or devices.
(2) status information . A Linux process can have several states: Run, wait, stop, and zombie.
(3) scheduling information . Based on this information, the scheduler determines which process in the system needs to be run most urgently.
(4) information about inter-process communication . The system uses this information to achieve inter-process communication.

5) information about the relationship between the process and other processes : In a Linux system, any process other than the root process has a parent process or a sibling process or child process. So the PCB for each process contains the parent process pointer of the process, and the sibling process pointer of the process with the same parent process, and the process's child process pointer. In addition, Linux uses a doubly linked list to record all the processes in the system, and the root of the doubly linked list is the init process. Using the information in this list, the kernel can easily find a process.
(6) Time and timer information . The system saves the process's settling time in these fields, as well as the CPU time spent in its life cycle. Linux also supports process-related timers, which the application can establish through system calls, and when the timer expires, the operating system sends a SIGALRM signal to the process.

(7) file System Information . This type of field records the file descriptor information that is opened by the process. It also contains pointers to the virtual file system (SYSTEMS,VFS) two index nodes, which are the master directory of the process and the current directory of the process, respectively. There is a reference counter in the index node, and the reference counter of the index node increases when a new process points to an index node. The reference count for an unreferenced index node is 0, so when a file that is contained in a directory is running, you cannot delete the directory because the reference count for this directory is greater than 0.
(8) virtual memory and physical memory related information : Each process has its own memory space, in order to let the Linux kernel at any time to understand and control the memory space of the process, the PCB must save the process memory space information.

(9) and process-related contextual information . A process context is a field used to hold the state of a process-related system. When the scheduler switches a process from a running state to a paused state, the current process is saved in context , including the value of all registers on the CPU, the state of the process, and the stack information, and when the scheduler selects the process to run again, The running environment of the process is restored from the process context information.

Process context
The so-called process context, which is a process at the time of execution, the value of all registers of the CPU, the state of the process, and the contents of the stack, when the kernel makes a process switch, it needs to save all the state of the current process, that is, the process context of the current process, so that when the process can be re-executed Continue execution.


4. Process Identifiers
The most important process identity in Linux:
process (PID, process idenity number)
Parent Process Number (PPID, parent procedure ID).
Where PID uniquely identifies a process, the kernel uses this identifier to identify different processes, and the user program dictates the process through the PID.
Both PID and Ppid are 32-bit unsigned integers
Process identity also has user and user group identification, process time, resource utilization, etc.

The PID and PPID system call functions that get the current process in Linux are Getpid () and Getppid ().

#include <stdio.h> #include <unistd.h> #include <stdlib.h>int main () {printf ("The PID of this process is %d \ n ", Getpid ());p rintf (" The PPID of this process is%d \ n ", Getppid ()); return 0;}
Running in Linux:




5. Status of the process running
Process is the process of execution of a program, according to its life cycle can be divided into 5 states (the first 3 of the basic state).
execution State: The process is running, that is, the process is consuming CPU.
Ready state: The process already has all the conditions for execution and is waiting to allocate CPU processing time slices.
waiting state: The process is waiting for an event or a resource. Wait states are divided into interruptible wait and non-disruptive wait two kinds. Interruptible wait processes can be signaled, while non-interruptible wait processes cannot be interrupted by a signal.
Stop state: When the process receives a sigstop signal, it is run into a stop state, and when the Sigcont signal is received, it resumes the running state, which is mainly used for debugging.
Zombie State (terminating State): The process has terminated, but its task_struct structure is still in memory. As the name implies, a process in this state is actually a dead process.

The status of the process runs as follows:




The various basic states of the process and their transformations:




Note: Linux under the compiler run C program detailed reference blog, (First day of training) The process of compiling and running C source program under Linux (diagram)

Little talk Process: The basic concept of Linux 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.