Process Management in Linux

Source: Internet
Author: User
Tags message queue terminates cpu usage

Linux process overview

A process is the basis of an operating system structure; an executing program; an instance of a program that is running on a computer; can be assigned to a processor

An entity that is executed by the processor, displayed by a single sequential execution, a current state, and a set of related system resources described by the active unit.

In other words, a process is an abstract concept, just as a program is an entity concept. The program is stored on disk containing executable machine instructions and data

Static entities, we can see a file that is an. exe file (under Windows) or any name executable (Unix, and other operating systems)

A process is a dynamic entity that performs specific tasks in the operating system. Each running program in a Linux system consists of at least one process, and each process

and other processes are independent of each other, have their own independent authority and responsibility. One user's application does not interfere with other users ' programs or actions

System itself.

The Linux operating system contains 3 different types of processes, each of which has its own characteristics and attributes.

1. Interactive process: There is a shell-initiated process. The interactive process can be run either in the foreground or in the background.

2. Batch process: This process is not associated with the terminal and is a sequence of processes.

3. Daemon: The process that the Linux system starts when it starts and runs in the background.

Linux process status

Usually in the operating system, the process must have at least 3 basic states, respectively, the operating state, the ready state and the blocking state (blocking state).

The running state refers to the state that the current process has allocated to the CPU and its program is executing on the processor. In this state of

The number of threads cannot be larger than the CPU. In a general single CPU mechanism, there is at most one of the processes that are in motion at any time.

A ready state is when a process already has a running condition, but because another process is taking up the cup, it cannot run temporarily and waits for allocation

The state of the CPU. Once the CPU is assigned to it, it can be run immediately, and in the operating system, the number of processes in the ready state may be multiple.

A blocking state is a signal that a process waits for an event to occur (such as waiting for an input/output operation to complete, waiting for another process to be sent)

, etc.) and temporarily unable to run the state. In other words, the blocked process does not yet have a running condition, even if the cup is idle, it

cannot be used. This state is sometimes also referred to as a non-moving or suspended state, and processes in this state can be multiple.

Manual start

User input command, directly start a process is the manual start process, but the manual start process can be divided into many kinds, according to

The types of processes that start are different, the properties are different, and the actual results are different.

Front start

The user enters a command "Ls-l, which has started a process and is a foreground process." This time the system has actually

In a multi-process state. Typically, when a user starts a process, many of the systems that are running in the background already exist, the system starts

Processes that have been started automatically.

Background boot

Manually starting a process directly from the background is less, unless the process is time consuming and the user is not in a hurry to see the results. Assume

The user is going to start a process for a long-running formatted text file so that the entire shell is not "paralyzed" during formatting

(No running results for a long time), it is wise to choose to start the process from the background.

There is a common feature of the two startup approaches, which is that the new process is generated by the current shell process. In other words, the shell creates

A new process has been built, and this relationship is called a parent-child relationship between processes. Here the shell is the parent process, and the new process is the child process. A parent process can

To have more than one child thread, generally, the child process ends before the parent process can continue: if you start from the background, you don't have to wait for the child process to end.

A special case is when you use a pipe symbol:

At the same time, 2 processes are started, both of which are child threads of the shell, and each sibling process.

Series commands in a process

The PS command is the most commonly used command to view the status of a process in Linux, showing processes running in the system, process numbers, commands, CPU usage, internal

The amount of storage used.

PS [Options]

-a displays information about all processes in the system that are related to TTY (except for the conversation leader).

-e displays information for all processes.

-F Displays all information about the process

-l display process information in long format

R shows only the running processes

U display user-oriented format (including information such as user name, CPU and memory usage)

X Show process information on all non-control terminals

--PID Displays the process information specified by the process ID

--tty displays process information on the specified terminal.

Pstree command

Each process in Linux is created by its parent process. This command displays the process visually, showing the process's tree graph to show

Inter-process relationships. You can also specify the root thread of the tree

Top command

The basic function of the top command and the PS command is the same, which shows the system's current process and its state, but top is a dynamic display process that can

To continuously refresh the current state via the user key. If the code is executed in the foreground, the command will monopolize the foreground until the user terminates the program. Top

General format of the command top [bciqss][d< interval seconds >][n< number of executions;]

b using Batch processing mode

C List The program, display the complete instructions for each program, including the instruction name, path and parameters and other related information

I execute the top command, suddenly idle or have become a zombie program

Q The status of continuous monitoring program execution

s use privacy mode to eliminate potential crises in interactive mode

S using cumulative mode

d< interval seconds;: Sets the time interval, in seconds, for top monitor execution.

n< number of executions;: Sets the number of updates to monitor information.

Update the status of running processes in the system in real time every 30 seconds using the top command

Nice command

With the help of the Nice command in Linux, the user can set and change the priority of the process. To increase the priority of a process, the kernel allocates more

Multiple CPU time slices to this process. By default, the process starts with a priority of 0. Process priority can be displayed by the top command for NI (nice value)

Column View

Process priority values range from 20 to 19. The lower the value, the higher the priority. If the adjusted program runs at a priority higher than-20, the priority-20来

The command line is run with the priority 19来 if the adjusted program runs at a priority lower than 19. If the nice command does not specify a priority adjustment value, the

Adjusts the program run priority with the default value of 10来, which is incremented by 10 on top of the current program run priority level.

Syntax:Nice [-n < priority;] [--help] [--version] [Execution instruction] Option Description:
-N < priority > assign priority;
--Help information;
--Version information;

sudo is a Linux system Management Directive, a tool that allows the system to administer some or all of the root commands for a common user, such as HALTREBOOT,SU and so on. This not only reduces the login and administration time of the root user, but also improves security. sudo is not a substitute for the shell, it is for each command. Rennice command

The Renice command is similar to the nice command, which allows you to change the running process precedence values. However, please note that the user can only change his

Their own process priority values.

GrammarRenice Priority [[-P] pid ...] [[-G] pgrp ... ] [[-u] user ...] parameter Description
    • -P PID Re-specifies the stroke's priority of the stroke with the ID of the PID
    • -G Pgrp re-specifies the priority of the stroke (one or more) of the itinerary group (process group) with an ID of PGRP
    • -U user re-specifies the priority order of the trip owner's itinerary for user
A process priority value of 1092th, with an initial value of 19, has become 4.

All process priority values of user root are changed to-3

Kill command

Normally terminating a foreground process can use the CTRL + C key combination, but for a background process it needs to be terminated with the KILL command. Kill command

Ends the process by sending the specified signal to the process. By default, a term signal with a programming number of 15 terminates all

The process of capturing the signal. For those processes that can capture the signal, it is necessary to forcibly kill the process with a kill signal numbered 9.

The general format of the KILL command is as follows:

Kill [-S signal |-p] process number

Kill-l [Signal]

-s specifies the signal to be sent, either the signal name (e.g. kill) or the number of the corresponding signal (e.g. 9)

-p Specifies that the KILL command simply shows the PID (process identification number) of the process and does not actually signal an end

-l display list of signal names

Ulimit command

The ulimit is used to start the resources that the process consumes. Most useful for system administrators, you can manage heavy usage and presence performance issues

the system. Restricting resource size ensures that important processes continue to run, and other processes do not consume excessive resources.
Syntax format:
Ulimit [-ACDFHLMNPSSTVW] [size]
Parameter description:
-H sets the hardware resource limit.
-S sets the software resource limit.
-a displays all current resource limits.
-C Size: Sets the maximum value of the core file. Unit: Blocks
-D Size: Sets the maximum value for the data segment. Unit: Kbytes
-F Size: Sets the maximum value of the created file. Unit: Blocks
-L Size: Sets the maximum value of the locked process in memory. Unit: Kbytes
-M Size: Sets the maximum number of resident memory that can be used. Unit: Kbytes
-N Size: Sets the maximum number of file descriptors that the kernel can open at the same time. Unit: N
-P Size: Sets the maximum value of the pipe buffer. Unit: Kbytes
-S size: Sets the maximum value of the stack. Unit: Kbytes
-T size: Sets the maximum CPU usage time limit. Unit: Seconds
-V Size: Sets the maximum value for virtual memory. Unit: Kbytes

W command

The W command provides information about the currently logged on user and the process that is being executed. Display information header contains information, such as current time, system run time

The total number of logged in users, the last 1, 5, and 15 minutes of load balancing.

The syntax format is as follows:

W-[HUSFV] [user]

The parameters are described below:

-H does not display the caption.

-U ignores the user name when the current process and CPU time are listed. This is primarily the case after the SU command is executed.

-S uses short mode. Logon hours, jcpu, and pcpu times are not displayed.

-F Toggle Displays the from entry, which is the remote host name entry. The default is to not display the remote host name, and of course the system administrator can make some modifications to the source file so that the item is displayed as the default value.

-V Displays version information.

The Who is a command similar to W that provides a list of currently logged-in users, system boot time, RunLevel, and so on.

WHOAMI command output current User ID

Pgrep command

The pgrep command looks up the process from the running process queue by name and displays the process ID that was found. Each process ID is represented by a decimal number, separated by a split string and the next ID, and the default split string is a new line. For each property option, a user can specify a collection of possible values separated by commas on the command line.

Syntax format

Pgrep (option) (parameter)

Parameters

-O: Displays only the minimum (start) process number found;

-N: Displays only the maximum (end) process number found;

-L: Show process name

-P: Specify parent process number

-G: Specify the process group

-T: Specifies the terminal on which the process is opened

-u: Specifies a valid user ID for the process.

IPCS command

The IPCS command reports inter-process communication facility status. (Shared memory, message volume and message queue) with-p parameter union-M,-s,-Q use

The process ID of the related interprocess communication can be obtained.

Process Management in 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.