Linux Advanced processes and threads

Source: Internet
Author: User
Tags switches

One, process and thread

1, Process: is a computer program on a data set on a running activity, is the system for resource allocation and tuning

is the basic unit of the operating system structure. In the early process design-oriented computer architecture, the process is the basic execution of the program

The process is a container of threads in a modern thread-oriented computer architecture. The program is the description of the instruction, the data and its organization

Process is the entity of the program. -----------Baidu Encyclopedia

In Linux, a process is a copy of a running program, a collection of instructions that is loaded into memory, using the process ID (PID) to mark

Individual processes. We can use echo $$ to see the process number of the current program.

[ [email protected] ~ ] #echo  $$          #  Gets the process number of the current bash 3267[ [email protected] ~ ]#[ [email protected] ~ ] #pstree  -psystemd (1) ─┬─networkmanager (520) ─┬─dhclient (623)             │                      ├─{networkmanager} (531)             │                      └─{networkmanager} (533)         .... Middle omitted ...            ├─sshd (935) ───sshd (3263) ───bash (3267) ───pstree (7269)            ├─systemd-journal (361)             ---|---            ├─systemd-logind (496)             #  Verified by Pstree, as with the results of echo $$               ├─SYSTEMD-UDEVD (380)            ├─tuned (920) ─┬─{tuned} ( 1105)            │             ├─{tuned} (1109)             │            ├─{tuned} (1111)             │             └─{tuned} (1116)             └─VMTOOLSD (495) [ [email protected] ~ ]# 
    • The permission that the process obtains, is the corresponding performer's permission, except Suid, Sgid and so on permission.

    • The process is a dynamic concept with a life cycle, with the ability to attach Sui, sgid and other privileges.

    • Process number is randomly assigned (the process number uniquely identifies a process; an inode uniquely identifies a disk file).

    • The first process in CentOS 6 and earlier systems is: SYSTEMD, the first process in Init;centos 7.

2. Guardian Process

A daemon (daemon) is a class of special processes that run in the background to perform specific system tasks. Many daemons are booting in the system

Start and run until the system shuts down. Others start only when they are needed, and end automatically when the task is completed.

The user makes the Daemon independent of all terminals because, in the case where the daemon is booted from a terminal, the same terminal may be

Used by his users.

The daemon does not control the terminal, so when certain situations occur, whether it is general reporting information or a tight

Need to be output in some way. The Syslog function is the standard way to output this information, which sends the message to SYSLOGD

Daemon process. For example, the program we use to monitor certain non-independent services, XINETD, is a super daemon for managing systems

Of the non-independent daemon (transient daemon), these non-isolated processes are typically in a closed state, which is supervised by the XINETD process

If someone uses the associated service, they wake up these non-independent daemons and work. We can use Chkconfig to view.

[[email protected] ~]# yum install xinetd         #  I'm using a minimal installation, and the XINETD service is not installed automatically [[email protected] ~]# chkconfig auditd              0:off    1:off     2:on    3:on    4:on    5:on     6:off    #  Independent Service autofs              0:off    1:off    2:on     3:on    4:on    5:on    6:o ffblk-availability    0:off    1:on    2:on     3:on    4:on    5:on    6:off ... Middle omitted Xinetd based services:           #  The following services are all non-independent services, from XINETD to manage      chargen-dgram:     off    chargen-stream:     off    daytime-dgram:     off     daytime-stream:    off    discard-dgram:      off    discard-stream:    off    echo-dgram:         off    echo-stream:        off    tcpmux-server:     off     time-dgram:        off    time-stream:        off[[email protected] ~]# chkconfig --add  Crond     #  Add Standalone service is not added to xinetd 

Note: Each time we add a service (chkconfig--add server_name) or delete a service (chkconfig--del server_name), we must restart the XINETD service (services restart XINETD).

3. Threads

Sometimes called a lightweight process (lightweight PROCESS,LWP), is the smallest unit of program execution flow. A standard thread consists of a

The thread ID, the current instruction pointer (PC), the Register collection, and the stack. In addition, a thread is an entity in a process that is independent of the system

The basic unit of dispatch and dispatch, the thread itself does not own system resources, only has a little in the operation of the necessary resources, but it can be

Other threads that belong to one process share all of the resources owned by the process.

One thread can create and revoke another thread, which can be executed concurrently between multiple threads in the same process. Because of the mutual constraints between threads, the thread is running in a discontinuous. Threads also have three basic states of readiness, blocking, and running. A ready state is a thread that has all of the conditions running, is logically capable of running, is waiting on a processing machine, and a running state is a thread-owning processor that is running; a blocking state is a thread waiting for an event, such as a semaphore, to be logically unenforceable.

Thread, then there is a multi-threaded argument. A thread is a single sequential control flow in a program. Within the process a relatively independent,

The execution unit of Dispatch is the unit of dispatch of the system which is independent dispatch and dispatch CPU, which refers to the running program. In a single program, the same

When you run multiple threads to do different work, called multithreading. Threads share the memory resources of the entire program, but there is also a thread out

Failure, affecting other threads, competing for resources. To avoid this contention for resources, the system joins the Lock Fork () mechanism clone ()

Mechanism. The principle of write-time replication is usually used:

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/A4/78/wKioL1msFuOSW5JVAAASdudXfuM516.png "title=" 123123 "alt=" Wkiol1msfuosw5jvaaasdudxfum516.png "/>

In Linux we can see through pstree that threads are typically represented as "{thread_name}" in the process tree.

[ [email protected] ~ ] #yum  -y install httpd  &>/dev/null[  [email protected] ~ ] #pstree  -psystemd (1) ─┬─networkmanager (520) ─┬─dhclient (623)            │                      ├─{networkmanager} (531)   # networkmanager Open multi-threaded            │                       └─{networkmanager} (533)             ├─ATD (509)            ├─AUDITD (471) ───{AUDITD} (482)            ├─automount (929) ─┬─{automount} (930)             │                 ├─{automount} (931)            │                 ├─{automount} (948)             │                 └─{automount} (960)             ├─crond (506)             ├─dbus-daemon (492) ───{dbus-daemon} (493)             ├─FIREWALLD (515) ───{firewalld} (619)            ├─httpd ( 7491) ─┬─httpd (7494)           # HTTPD Services open multiple processes             │              ├─HTTPD (7495)            │              ├─HTTPD (7496)             │             ├─HTTPD (7497)            │              └─HTTPD (7498)            &NBSP, ..... Omitted after ... [ [email protected] ~ ]#


4. Thread-to-process relationships

    • A process can contain multiple threads;

    • Each program has at least one thread, if the program has only one thread, that is the program itself;

    • Address space and other resources (such as open files): Processes are independent of each other and shared among threads of the same process. Threads within a process are not visible in other processes.

    • Communication: Inter-process communication IPC, between threads can directly read and write process data segments (such as global variables) to communicate--requires process synchronization and mutual exclusion means of support to ensure data consistency.

    • Scheduling and switching: Thread context switches are much faster than process context switches.

    • In a multithreaded OS, a process is not an executable entity.

Ii. priority of the process

Sometimes we face a lot of choices, at the same time there are a lot of things to do, then we will always have a selective implementation, what to do after what, this is a priority, the same as a high-speed computer, the order of priority agreement is very important.

Priority is a convention in which priority is done first, followed by a low priority. Priority is the computer's time-sharing operating system

Determines the parameters that each job program accepts as a priority for system resources when it processes multiple operating procedures. Priority is the computer operating system gives any

Priority level specified by the service. It determines the priority of the task when it uses the resource. The priority level assigned to the device. It decided that the equipment was being presented

When the request is interrupted, the order of the processing machine response is obtained. Priority of task scheduling is the priority of the task being scheduled to run, mainly

is related to the priority of the task itself and the scheduling algorithm. Especially in real-time systems, task scheduling priorities reflect a task's importance and tight

Forced sex. -------Baidu Encyclopedia

1. System priority

Process priorities work in a way that hasn't changed much since the invention, whether it's a CPU-only era or a multicore CPU

Generation, which is achieved by controlling the length of CPU time that the process consumes. This means that in the same scheduling cycle, high-priority processes occupy

Longer, while low-priority processes take up less. System priorities in Linux systems range from 0-139 to 140 and rank

, the lower the value, the higher the priority, and the range of system priority after CentOS 6 becomes 0-98.

2, real-time priority

Real-time priority is also called dynamic priority, its range is 0-99, the higher the value, the higher the priority, the dynamic priority can not be artificially adjusted, the system

Dispatch itself.

3. Static priority

    • Static priority is also called non-real-time priority: it is usually expressed with nice value;

    • The nice value range corresponds to the system priority of 100-139; The value is: -20~19;

    • The nice value is 0 when the process is started by default, and the priority level is 120;

    • Only the root user can reduce the nice value (increase priority);

    • Nice priority the smaller the value, the higher the priority;

4, three priority relationships

There is a corresponding relationship between system priority, real-time priority, nice value, and its relationships such as:

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/05/C8/wKiom1msIV7zrPlEAAALP0l0ttY623.png "title=" 123 " alt= "Wkiom1msiv7zrpleaaalp0l0tty623.png"/>

This article is from the "vinsent" blog, make sure to keep this source http://vinsent.blog.51cto.com/13116656/1962388

Linux Advanced processes and threads

Related Article

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.