Linux Program management: How to use commands such as Top.htop.glances,dstat

Source: Internet
Author: User
Tags message queue network function cpu usage

Linux Program management: How to use commands such as Top.htop.glances,dstat



The difference between a process and a thread:

Defined:

Process is a program with certain independent function, and it is an independent unit of resource allocation and dispatch of the system.

A thread is an entity of a process that is the basic unit of CPU dispatch and dispatch, which is a smaller unit that can run independently than a process. The thread itself basically does not own system resources, it only has a bit of resources that are essential in the run, but it can share all of the resources owned by the process with other threads that belong to one process.

Difference:

The main difference between processes and threads is that they are different ways to manage operating system resources. The process has a separate address space, and after a process crashes, it does not affect other processes in protected mode, and the thread is just a different execution path in a process. Thread has its own stack and local variables, but there is no separate address space between the threads, a thread dead is equal to the entire process dead, so the multi-process program is more robust than multithreaded programs, but in the process of switching, the cost of large resources, efficiency is worse. But for some concurrent operations that require simultaneous and shared variables, only threads can be used, and processes cannot be used.

What is a process?

In a Linux system: when triggering any event, the system defines it as a process, and gives the process an ID, called a PID, and gives the PID a set of valid all-township settings based on the user and related attributes that triggered the process. A program is a binary file that starts when the system is working. The program is typically on disk, triggered by the user's execution, and then loaded into memory as an individual, that is, a process. A process that resides in memory is usually responsible for the functionality provided by some systems to serve the user's tasks, so these resident processes are called services

Summarize:

1) In short, a program has at least one process, and a process has at least one thread.

2) The thread partition scale is smaller than the process, which makes the multi-thread procedure high concurrency.

3) In addition, the process has a separate memory unit during execution, while multiple threads share memory, which greatly improves the efficiency of the program operation.

4) threads are still different from the process in the execution process. Each separate thread has a program run entry, sequence of sequence execution, and exit of the program. However, threads cannot be executed independently, and must be dependent on the application, which provides multiple threads of execution control.

5) from a logical point of view, the meaning of multithreading is that in an application, there are multiple execution parts that can be executed concurrently. However, the operating system does not consider multiple threads as separate applications to implement scheduling and management of processes and resource allocation. This is the important difference between processes and threads.

Ways to send foreground jobs back to the background:

With & or CTRL + Z:

Cases:

1

2

3

4

5

6

[Email protected] ~]# cp-r/etc//tmp/etc &

[1] 2610

[[email protected] ~]# jobs

[1]+ Running cp-i-r/etc//tmp/etc &

[[email protected] ~]# jobs

[1]+ done Cp-i-r/etc//tmp/etc


Cases:

Vim A.txt

CTRL + Z

Jobs Command Usage:

Jobs [-lrs]

-L: The PID number is listed in addition to listing Jobnumber

-r: List only jobs in background run

-S: Lists only jobs in the background stop


Example: BG%1

Manage jobs in the background kill command:

List the signals that kill can use: kill-l

1

2

3

4

5

6

7

8

9

10

11

12

13

14

[Email protected] ~]# kill-l

1) SIGHUP 2) SIGINT 3) Sigquit 4) Sigill 5) SIGTRAP

6) SIGABRT 7) Sigbus 8) SIGFPE 9) SIGKILL) SIGUSR1

One) (SIGSEGV) (SIGUSR2) sigpipe) sigalrm) SIGTERM

Sigstkflt) (SIGCHLD) Sigcont SIGSTOP) SIGTSTP

(Sigttin) Sigttou () Sigurg) sigxcpu) Sigxfsz

(SIGVTALRM) sigprof) sigwinch SIGIO) SIGPWR

Sigsys) (sigrtmin) sigrtmin+1) sigrtmin+2 Notoginseng) sigrtmin+3

sigrtmin+4) sigrtmin+5 (sigrtmin+6) sigrtmin+7) sigrtmin+8

sigrtmin+9) (sigrtmin+10) sigrtmin+11 () sigrtmin+12) sigrtmin+13

(sigrtmin+14) sigrtmin+15 () SIGRTMAX-14) SIGRTMAX-13) SIGRTMAX-12

SIGRTMAX-11) SIGRTMAX-10 SIGRTMAX-9) SIGRTMAX-8 () SIGRTMAX-7

(SIGRTMAX-6) (SIGRTMAX-5) SIGRTMAX-4) SIGRTMAX-3) SIGRTMAX-2

SIGRTMAX-1) Sigrtmax

Kill-Signal Digital%jobnumber

1 re-read the configuration file

-2 interrupts, same as CTRL + C

-9 Force Delete a job

-15 Terminate a job in the normal way

Note-91 is used to force the deletion of an unhealthy job, 15 is to end a job with normal steps (15 is also the default value)

Example: kill-9%1

Process Management:

1. Process View:

Pstree Command usage:

Pstree command: Process tree view;

-P: Shows the PID of each process;

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

[Email protected] ~]# Pstree

Init─┬─abrtd

├─acpid

├─atd

├─AUDITD───{AUDITD}

├─automount───4*[{automount}]

├─CONSOLE-KIT-DAE───63*[{CONSOLE-KIT-DA}]

├─crond

├─cupsd

├─dbus-daemon

├─dhclient

├─hald─┬─hald-runner─┬─hald-addon-acpi

││└─hald-addon-inpu

│└─{hald}

├─login───bash

├─master─┬─pickup

│└─qmgr

├─5*[mingetty]

├─rpc.statd

├─rpcbind

├─RSYSLOGD───3*[{RSYSLOGD}]

├─sshd───sshd───bash───pstree

└─UDEVD───2*[UDEVD]

PS Command usage:

PS: Select the process run at a point in time

Depending on whether the process started interactively from the user interface on the terminal, the process can be divided into two categories:

Terminal-related processes: a

Terminal-independent processes: X

User-centric organization of process status information display: U

S:session the first process of the leader session process

+: Foreground process, occupy a terminal

L: Multithreaded Process

<: high-priority process

N: Low-priority process

Start: Startup time

Time: Occupy CPU cumulative duration

Command: Starts the shell of the current process or thread, [] represents a kernel thread;

Common option Combination 2:-ef

-e: Show All Processes;

-F: Display rich formatting information

Common option Combination 3:-EFH

-F: Show additional information

-H: Show the inter-process relationship in a hierarchical form;

Customizing the information you need to display: Axo

PS Axo Pid,command,psr,pri,ni

PSR: The CPU number of the current process running;

PRI: Priority of the current process;

NI: The nice value of the current process;

-20, 19

Pgrep: Filter displays only specified information

Syntax format: pgrep [OPTIONS] "PATTERN"

-U UID: Displays only the processes running as the specified user;

-G GID

-L: Show PID and process name;

Pidof: Gets the ID number of a running program

Example: Pidof/bin/bash

1

2

[Email protected] ~]# Pidof/bin/bash

2476 1844

Top Command usage:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

[email protected] ~]# Top

top-15:10:38 up 3:53, 2 users, Load average:0.00, 0.00, 0.00

tasks:94 Total, 1 running, sleeping, 0 stopped, 0 zombie

Cpu (s): 0.0%us, 0.2%sy, 0.0%ni, 99.5%id, 0.2%wa, 0.0%hi, 0.1%si, 0.0%st

mem:1004352k Total, 430648k used, 573704k free, 34504k buffers

swap:2097148k Total, 0k used, 2097148k free, 287016k cached

PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND

2985 Root 0 15032 1092 828 R 2.0 0.1 0:00.05 Top

1 Root 0 19356 1536 1224 S 0.0 0.2 0:00.85 Init

2 Root 0 0 0 0 S 0.0 0.0 0:00.00 Kthreadd

3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0

4 Root 0 0 0 0 S 0.0 0.0 0:00.03 ksoftirqd/0

     5 root     &NBSP;RT   0     0    0    0 S  0.0 &N bsp;0.0   0:00.00 stopper/0                         &NBSP ;                          ,         &NB Sp                                

     6 root     &NBSP;RT   0     0    0    0 S  0.0 &N bsp;0.0   0:00.03 watchdog/0                         &NBS P                          ,         &NB Sp                                 

     7 root      20   0     0    0    0 S  0.0 &N bsp;0.0   0:12.81 events/0                                                    ,         &N Bsp                                 &NBSP;&NBS P;

8 Root 0 0 0 0 S 0.0 0.0 0:00.00 Cgroup

9 Root 0 0 0 0 S 0.0 0.0 0:00.00 khelper

First line (top ...) : The information shown in this line is:

The current time, that is, 14:34:29 that project;

The time that has elapsed so far, that is, the project of up 3:17;

The number of users who have logged into the system, that is, the 2 user project;

The system averages the workload at 1, 5, 15 minutes. Batch works by a load of less than 0.7, representing 1, 5, 15 minutes, the system is responsible for the average operation of several programs (work) meaning. The smaller the system, the more idle it is, and the more 1 you have to pay attention to whether your system is too cumbersome. Reasonable interval of general queue Length: number of CPUs *0.7. Uptime command: Displays the current system time, the running time, the number of users logged in and the average system load;

Second row (Tasks ...) :

Shows the total amount of the current program with the individual program in what state (running, sleeping, stopped, zombie). The more important thing to note is the last zombie that value.

Third line (Cpus ...) :

Shows the overall CPU load, which can be used for each project? Inspection. Special attention is%WA, the project represents I/O wait, usually your system will be slow is the problem of I/O is relatively large! So it's important to note that this project consumes CPU resources. In addition, if the device is multi-core, you can press the number key ' 1 ' to switch to different CPU load rate.

Line four and line fifth:

Represents the current use of physical memory and virtual memory (MEM/SWAP). It is important to note that the amount of swap should be used as little as possible! If swap is used a lot, it means that the physical memory of the system is not enough!

Line six: This is where the state is displayed when the command is entered in the top program.

For the top lower half of the screen, it is the resource situation used by each process. The comparison needs to be noted:

PID: ID 6 for each process

User: The user to whom the process belongs;

Pr:priority, the priority order of the program, the smaller the sooner it is executed;

The abbreviation of Ni:nice, which is related to priority, is also smaller and sooner executed;

VIRT: virtual memory;

RES: Resident memory;

SHR: Shared memory;

S: State;

%cpu:cpu of the use rate;

%MEM: Memory utilization;

Time+: Cumulative use of CPU time;

Command: Shell

P: Sort by the percentage of CPU occupied;

M: In order to occupy memory space size;

T:CPU cumulative occupancy time sequencing;

L: Whether the system load line is displayed;

Reasonable interval of queue Length: number of CPUs *0.7

Uptime command: Displays the current system time, the running time, the number of users logged in and the average system load;

1

2

[Email protected] ~]# uptime

15:11:33 up 3:54, 2 users, Load average:0.00, 0.00, 0.00

T: whether to display the process summary information and CPU load status;

Cpu (s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

Us:user Space

Percentage of CPU occupied by running the user program

Sy:system (kernel space)

Percentage of CPU occupied by running kernel programs

Ni:nice

Percentage of CPU affected after adjusting the nice value

Id:idle

Percentage of idle CPU

Wa:wait IO

Percentage of CPU waiting for I/O completion to occupy

Hi:hardware Interrupt

Percentage of CPU processing hardware interrupts occupied

Si:software Interrupt

Percentage of CPU processing software interrupts occupied

St:stolen

Percentage of CPU "stolen" by virtualization technology

General Us:sy for 7:3 Best

1: Average or separate display of CPU load status;

M: Whether to display memory-related status information;

Q: Exit command

S: Modify the delay length

K: Terminates the specified process

Options for the top command:

-b:batch, Batch Display

-N #: Number of batches displayed

-D #: Indicates how long the delay is

Htop Command usage:

Wkiom1uudnhswohgaabm5kzdjgw180.jpg

F1 Help Information

F2 settings

F3 Search

F4 Filtration

F5 is displayed in a tree-like structure

F6 Sort by what

F7/f8 setting Nice values

F9 terminating a process

F10 exit

U: Filter only displays the process of the selected user; [Options Bar appears on the left]

S: Tracks the system calls initiated by the selected process; [Select a process press the S key]

L: Displays the file opened by the selected process; [Select a process press the L key]

T: Displays the hierarchy of processes, as with F5; [Select a process by pressing the T key]

A: Sets the CPU affinity of the process; (binds the selected process to the specified CPU)

Options:

-D #: Delay duration

-U USERNAME: Displays only the process of the specified user;

-S COLUMN: Sorts according to the specified field;

Mvstat Command usage:

Viewing the use of virtual memory

Vmstat-s Display status statistics for memory


Process-related (procs) projects are:

R: The number of processes waiting to be run, that is, how many are waiting for the operation; (Queue Length)

B: The number of programs that cannot be awakened, that is, the number of processes that handle non-disruptive sleep states; (i.e. IO blocking queue Length)

The more these two projects, the busier the system is (because the system is too busy, so many programs cannot be executed or are waiting to be woken up).

Memory items are:

SWPD: Swap memory usage;

Free: The amount of physical memory in space;

Buffer: The total amount of memory used for buffering;

Cache: The total amount of memory used for caching;

The items in memory swap space (swap) are:

Si: The rate at which data enters the swap (KB/S)

So: the rate at which data leaves swap (kb/s)

If the value of si/so is too large, it means that the physical memory is not enough, indicating that the data in memory is often transmitted between disk and memory, and the system is inefficient.

Disk read-write (IO) items are:

BI: The rate at which data is read from the block device to the system (KB/S)

Bo: The rate at which data is saved to a block device (KB/S)

If the value of this part is higher, the I/O representing the process in the system is very busy.

Systems (System) projects are:

In: Number of programs interrupted per second;

CS: The number of event switches per second;

The larger the two values, the more frequent the system communicates with the peripherals! These peripherals, of course, include disks, network cards, clocks, and so on.

The CPU items are described in more detail in [Top]:

US: CPU usage status of non-core layer;

SY: The CPU state used by the core layer;

ID: idle state;

WA: CPU state required to wait for I/O;

ST: CPU usage State stolen by virtual machine.


Glances command usage [Epel]:

Process View Tool

Wkiol1uugfqtrp4_aaptrogszvo043.jpg

Common options:

-B: Display the data exchange rate of the network card device in BYTE/S;

-D: Turn off the disk I/O function module;

-f/path/to/somefile: Set the location and format of the output file;

-O html| CSV: Using Html/csv format

-M: Turn off the Mount function module

-N: Turn off network function module

-r: Close Process List Function module

-T #: Specifies the length of the delay, which defaults to 3 seconds;

-1: Display each CPU related load data information separately;


Glances supports remote mode:

That can work in C/s mode:

Server: Start glances in listening mode;

Client: Start glances in remote mode, connect to the specified server remotely, and display the correlation performance data on the server;

Service mode:

Glances-s-B Local IP address

-B: Used to indicate the local address of the listener;

Client mode:

GLANCES-C Server IP Address

-C: The address of the server used for the connection;

Example: Performing glances-s-B 192.168.1.108 on 192.168.1.108

Perform glances-c 192.168.1.108 on 192.168.1.106

Note: You may not be able to connect due to firewall reasons



Dstat Command usage:

A multipurpose tool for statistical system resource data, integrating the functions of Vmstat, Iostat, Netstat and ifstat four tools;

-G: Displays page-related rate data;

-I: Show interrupt related rate data;

-L: Display loadaverage related statistics;

-M: Display memory related statistics;

-N: Shows the rate of data sent and received by the network;

-P: Displays process-related statistics;

The rate of-r:io requests;

-S: Shows the relevant data of swap;

-Y: Displays system-related data, including interrupts and process switching;

--TOP-CPU: Displays the most CPU-intensive processes;

--top-bio: Shows the process that consumes Blockio most;

--top-io: The most IO-intensive process;

--top-mem: Shows the most memory-intensive processes;

--IPC: Shows the rate data related to interprocess communication;

--raw: Displays data related to raw sockets;

--TCP: Displays data related to TCP sockets;

--UDP: Displays data related to UDP sockets;

--unix: Displays statistical data related to Unixsock interface;

--socket: Display socket, equivalent to--raw--tcp--udp with

-A: Displays CPU, disk, network, page, system-related information, equivalent to-cdngy


Kill command Usage:

IPC: Inter-process communication

Common forms:

Message Queue

Semerphore

Shared memory

Signal

Signal: Short information passed to a process

Information that is available between processes supported by Linux hosts:

(1) kill-l [above Jobs ' description]

(2) Man 7 signal

Signal to process:

Kill[-signal] PID

The default signal is sigterm;

Signal Indication:

1 Full name, SIGINT

2 Shorthand name, INT

3 Data McCartney, 2

Common signals:

SIGHUP

1

Notifies the process to reread its configuration file for the new configuration to take effect without restarting the process

SIGINT

2

Interrupts a running process, equivalent to a keyboard key combination CTRL + C

SIGKILL

9

Forcibly aborting a running process

SIGTERM

15

Safely aborting a running process

SIGSTOP

19

Pausing a process

Sigcont

18

Run the specified process

Kill a similar set of processes:

Killall[-signal] Program


Process Priority tuning:

Static priority:

The priority is adjusted by specifying the nice value of the process, and the process of user space running generally has its nice value;

By virtual machine Nice value: -20,19

Their priority level: 100, 139


This article is from the "Lu Hang @ blog" blog, please be sure to keep this source http://10116624.blog.51cto.com/10106624/1657744

Linux Program management: How to use commands such as Top.htop.glances,dstat

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.