System processes for Linux

Source: Internet
Author: User
Tags mutex set time terminates

Linux Process Management
In a Linux system, triggering any event, the system will define it as a process, and give the process an ID, called PID. At the same time, based on the relationship between the user triggering this process and the related attributes, give this PID a set of valid permission settings.

Process Basic Concepts
I. Processes and Procedures
Program
A program is an ordered set of static instructions, which is a static concept.
Usually the binary program is placed in the storage medium (such as hard disk, CD-ROM, etc.), in the form of physical files, such as:/ETC/INIT.D/HTTPD itself is a software code;

Process
A process is a running activity of a program and belongs to a dynamic concept.
After the program is triggered, the performer's permissions and properties, program code and required data will be loaded into memory, and the operating system will give the memory unit a PID, such as: If the start/etc/init.d/httpd will produce a corresponding process;

Attention
Procedures and processes do not correspond to each other, a program can be shared by multiple processes, a process in the activity can be executed sequentially several programs;

Ii. Processes and Threads
We use a case to understand these 2 nouns:
Person: thread; table: process; Open a table: process overhead

Write a picture description here

A process is the smallest unit of resource scheduling, and a thread is the smallest unit of CPU scheduling.

Iii. child processes and parent processes
In a Linux system, the system calls fork to create the process, which is a process produced by a process that produces the process of the child process as the parent process

Let's take a look at an experiment
Write a picture description here
As you can see from the previous example, the parent process of the latter process is the previous process

Under normal circumstances, the parent process terminates the child process, in particular:

    • Orphan process: The parent process terminates, the child process is not terminated, the child process becomes an orphan process, and its parent process automatically points to the INIT process;
    • Zombie Process: Dad didn't know my stupid son had hung up, so his son became a zombie (process);
      We can use Ps-z to find the zombie process, and then use Kill-s singnal pid to kill him, notice that this PID is the ID of the parent process (the zombie process itself is dead, you can not kill dead people ~ ~)
    • Deadlock: A number of processes/threads in the execution process, because of the contention for resources to create trust and wait for the phenomenon;

Iv. foreground process and background process
Foreground process
After the shell prompts for the break command, creates a subprocess, runs the command, the shell waits for the command to exit, and then returns to the user prompt, which runs asynchronously with the shell, which runs in the foreground, and the user cannot execute another command until it finishes.

Background process
After the shell prompts for the break command, followed by a &, run the command, the shell creates a child process to run this command, but does not wait for the command to exit, directly back to the user prompt, this command runs synchronously with the shell, that is, the background runs.

V. Several states of the process
The main difference between the process and the program is the dynamic, dynamic generation and termination, from the generation process to the termination process can have the basic state of the ready state, the running state, the blocking state

Ready state: When the process has been assigned to the necessary resources other than the CPU, as long as the CPU is obtained, it can be executed immediately, then the state is called the Ready state;
Running state: The process has gained CPU and its program is executing;
Wait state: The execution of the process is blocked, for example: request I/O, buffer space, and so on, this pause state is called blocking state, also known as blocking state.
#通常将相同状态的进程排成一个或者多个队列, such as: Ready queue, blocking queue, etc.;

Stage of the process?
There are 3 stages in the lifetime of a process: Wait, run, stop (after successful execution or after receiving the kill process signal);
In particular, the process of killing is still left in the process table and is the zombie;
Vi. process Scheduling
When you run a program, the system generates a parent process and calls fork to copy several sub-processes, and then suspends the process to load the actual program to execute, and when the child process terminates, returns an exit signal, and the parent process calls the wait command to read the child process status to death. Then the handle process is removed from the process table;

Fork
The system first copies the same intermediate cache sub-process as the parent process by fork
The only difference is that the PID is different, and the staging process will have one more ppid parameter

Write a picture here to describe how the child process implements inheritance?
Fork replication includes the data and stack segments of the parent process and the process environment of the parent process, enabling the child process to implement the inheritance

Exec
Then the staging process begins to load the actual program to be executed in EXEC mode, the new process is named Daidai, and the program code of the final subprocess is Daidai

Synchronous
Synchronization mechanism
Critical section: Only one thread is allowed to access the shared resource process at any time, applicable to internal processes
Mutex: Has a mutex object permission to access the resource, the object has only one;
Semaphore: Allows multiple threads to access the same resource at the same time; (similar to operating system pv,p request operation, v release operation)
Events: Keeping threads in sync by notifying actions

Synchronous communication

System-level kernel processes are enclosed in brackets, which perform some of the system's accessibility functions (such as writing the cache to disk), and the processes that are executed by the user (such as PHP, Nginx, and so on).

10 more common system processes:

Kswapd0
Kjournald
Pdflush
Kthreadd
Migration
Watchdog
Events
Kblockd
Aio
Rpciod

1, kswapd0
Every time the system will wake up KSWAPD, see if the memory is tense, if not tense, then sleep, in the KSWAPD, there are 2 thresholds, pages_hige and Pages_low, when the number of free memory pages less than Pages_low, The KSWAPD process scans the memory and releases 32 free pages at a time, until the number of the zero page reaches Pages_high.

2, Kjournald
Journal: Record metadata changes on all file systems, one of the slowest modes.
Ordered: The default mode, which records only the metadata of the file system changes, and logs the log before it is changed.
Writeback: The fastest mode, which also records only modified metadata, relies on the standard file system write process to write data to the hard disk.

3, Pdflush
The Pdflush is used to synchronize the in-memory content with the file system.

4, Kthreadd
This kernel thread has only one function, which is to manage the dispatch of other kernel threads.

5, migration

This kernel thread has a total of 32, from migration/0 to MIGRATION/31, each processor core corresponds to a migration kernel thread, the main role is as the corresponding CPU core migration process, to perform process migration operations, the function in the kernel is Migration_ Thread ()

A load-balancing system belonging to the 2.6 kernel that automatically loads (one per CPU) at system startup and sets itself as a real-time process for Sched_fifo, and then checks to see if there are requests waiting to be processed in runqueue::migration_queue, if not, Sleep in task_interruptible until it is awakened and then checked again. Migration_thread () is just one interface for CPU bindings and functions such as CPU power management. This thread is an important part of the dispatch system.

6, watchdog

This kernel thread has 32, from watchdog/0 to WATCHDOG/31, each processor core corresponds to a watchdog kernel thread, watchdog is used to monitor the operation of the system and automatically restarts the system in the event of a system failure, including a kernel watchdog module and a user-space watchdog program.

Under the Linux kernel, the basic principle of watchdog is: When the watchdog is started (that is, after the/dev/watchdog device is opened), if in a set time interval (1 minutes)/dev/watchdog has not been performed the write operation, The hardware watchdog circuit or software timer restarts the system, and each write operation causes the timer to be reset.

7. Events

There are 32 kernel threads, from events/0 to Events/31, each of which corresponds to an events kernel thread. Many hardware and software events (such as power outages, file changes) that are used to handle kernel events are converted to events and distributed to the threads that are interested in the corresponding event response.

8, KBLOCKD

There are 32 kernel threads, from kblockd/0 to Kblockd/31, each of which corresponds to a KBLOCKD kernel thread. A block device used to manage a system that periodically activates block device drivers within the system. If you have a block device, these threads cannot be removed.

9. Aio

This kernel thread has 32, from aio/0 to AIO/31, each processor core corresponding to an AIO kernel thread, in lieu of user process management I/O, to support user-state AIO (asynchronous I/O), should not be closed.

10, Rpciod

This kernel thread has a total of 32, from rpciod/0 to RPCIOD/31, each processor core corresponds to a rpciod kernel thread, the main role is to serve as a daemon for remote process Call service, to start the I/O service from the client, it is usually used to start the NFS service.

Summarize

A process is a very important concept on the operating system, and all of the data running on it will exist in the type of process. In a Linux system: Whenever an event is triggered, the system defines it as a process, so the process is the only way to implement a Linux program.

The PS command is used to view the status of the process in the system, in the format: "ps [parameter]",
Common PS command parameters include the following:
-A shows all processes (including other users)
-u user and other details
-X shows no control of the terminal process

The most common 5 different states of a process in a Linux system are run, interrupt, non-disruptive, zombie, and stop
R (Run): Running or waiting in the running queue.
S (interrupt): Dormant, waiting for a condition to form or receive a signal.
D (non-interruptible): The received signal does not wake up and is not operational, the process must wait until there is an interrupt.
Z: (Zombie): The process has terminated, but the process descriptor exists until the parent process calls WAIT4 () after the system call is released.
T: (STOP): Process received Sigstop, SIGSTP, Sigtin, Sigtou signal after stop operation.

How to turn off unwanted processes under the Linux system:
First Chkconifig--list View the process name you want to close and then Chkconfig service name off

System processes for Linux

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.