Linux process and Job management

Source: Internet
Author: User
Tags network function terminates pkill

Function of kernel: process management, file system, network function, memory management, driver, security function

Process: A copy of a running program that has a life cycle

Fixed format for Linux kernel storage process information: task struct

Linked list of task struct components for multiple tasks: Task List

Process creation:

Init

Parent-child Relationship

Process: all created by its parent process

Process priority:

0-139:

1-99: Real-time priority

100-139: Static priority (the smaller the number, the higher the priority)

Nice value: -20,19

Process Memory:

Page frame: Pages box for storing page data

Store page

Mmu:memory Management Unit

Ipc:inter Process Communication

On the same host:

Signal, shm:shared memory, Semerphor

On different hosts:

Rpc:remote procecure Call, Socket:


Linux kernel: Preemptive multi-tasking

Process Type:

Daemon: A process initiated during a system boot process that is not related to a terminal

Foreground process: terminal-related, process initiated through terminal

Note: You can also send the foreground-initiated process to the background to run in daemon mode.

Process Status:

Operating state: Running

Ready state: Readiness

Sleep state:

Interruptible: interruptable

Non-disruptive: uninterruptable

Stop state: Paused in memory, but not dispatched unless manually initiated; stopped

Zombie State: Zombie


Classification of processes:

Cpu-bound

Io-bound


Tools for viewing and managing Linux processes: Pstree, PS, Pidof, Pgrep, Top, htop, glance, Pmap, Vmstat, Dstat, Kill, Pkill, job, BG, FG, Nohup

Pstree command:

Pstree-display a tree of processes


Ps:process State

Ps-report a snapshot of the current processes

Information about each process in the Linux system is stored in each file in the/proc/pid directory

PS [OPTION] ...

Options: Support two styles

Common combination: aux

U: Display of process status information in user-centric organization

A: terminal-related processes

X: Terminal-independent processes

~]# PS aux

USER PID%cpu%MEM VSZ RSS TTY STAT START time COMMAND

Vsz:virtual memory SiZe, set of virtual memories

Rss:resident Size, resident memory set

STAT: Process Status

R:running

S:interruptable sleeping

D:uninterruptable sleeping

t:stopped

Z:zombie

+: Foreground process

L: Multithreaded Process

N: Low-priority process

<: high-priority process

S:session leader

Common combination:-ef

-e: Show All Processes

-F: Display full format program information


Common combination:-EFH

-F: Show process information in full format

-H: Show process-related information in process-level format


Common combination:-eo, Axo

-eo Pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,comm

Axo Stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm

Ni:nice value

Pri:priority, priority

Psr:processor, CPU

Rtprio: Real-time priority


Pgrep, Pkill:

pgrep [Options] Pattern

Pkill [Options] Pattern

-U uid:effective User

-U uid:real User

-T terminal: processes associated with the specified terminal

-L: Show process name

-A: Displays the process name in full format

-P PID: Displays a list of processes whose parent process is specified for this purpose


Pidof:

Get its PID based on the process name


Top

There are many built-in commands:

Sort:

P: Percentage of CPU occupied

M: Percentage of memory occupied

T: Cumulative Occupy CPU duration

The first message shows:

Uptime information: l command

Tasks and CPU information: T command

CPU Display: 1 (digital)

Memory Information: M command

Exit Command: Q

Modify Refresh time interval: s

Terminates the specified process: K

Options:

-D #: Specifies the refresh interval, which defaults to 3 seconds

-B: In batch mode

-N #: Shows how many batches


Htop command:

Options:

-D #: Specify the delay time

-U UserName: Displays only the processes of the specified user

-S Colomn: Sorting in the specified field

Command:

S: Track system calls for selected processes

L: Displays the list of files opened by the selected process

A: Binds the selected process to a specified CPU core

T: Show Process Tree


Vmstat command:

Vmstat [Options] [delay [count]]

Procs:

R: Number of processes waiting to run

B: The number of processes in the non-interruptible sleep state (the length of the blocked queue)

Memory

SWPD: Total amount of swap memory used

Free: Total Idle physical memory

Buffer: The total amount of memory used for buffer

Cache: The total amount of memory used for the cache

Swap

SI: Data rate for data entry into swap (KB/S)

So: Data rate from swap (KB/S)

Io:

BI: The rate at which data is read into the system from the block device; (kb/s)

Bo: The rate at which data is saved to a block device

System

In:interrupts, Interrupt rate

Cs:context switch, process switching rate

Cpu:

US, SY, ID, WA, ST

Options:

-S: Show memory statistics


PMAP command:

Pmap-report memory Map of a process

PMAP [options] pid [...]

-X: Displays detailed format information;

Another implementation:

# Cat/proc/pid/maps


Glances command:

glances [-BDEHMNRSVYZ1] [-B bind] [-C Server] [-C conffile] [-P port] [-p password] [--password] [-t refresh] [-f file] [- O Output]

Built-in commands:

A Sort processes automatically l Show/hide logs

C Sort processes by CPU% b Bytes or bits for network I/O

M Sort processes by mem% W Delete warning logs

P Sort processes by name X Delete Warning and critical logs

I Sort processes by I/O rate 1 Global CPU or PER-CPU stats

d show/hide disk I/o stats h show/hide

F show/hide File system stats T View network I/O as combination

n show/hide Network stats u View Cumulative network I/O

s show/hide Sensors stats Q Quit (ESC and ctrl-c also work)

Y show/hide hddtemp Stats

Common options:

-B: Display nic data rate in bytes

-D: Turn off the disk I/O module

-f/path/to/somefile: Setting the input file location

-O {html| CSV}: Output format

-M: Disable Mount Module

-N: Disable network module

-T #: Delay time interval

-1: Each CPU related data is displayed separately

Run the glances command in C/s mode:

Service mode:

Glances-s-B ipaddr

IPADDR: Indicates which address is listening on this machine

Client mode:

Glances-c ipaddr

IPADDR: Server-side address to connect to


Dstat command:

Dstat [-AFV] [options:] [Delay [Count]]

-C: Display CPU-related information

-C #,#,..., Total

-D: Show disk-related information

-D Total,sda,sdb,...

-G: Display page related statistics

-M: Display Memory related statistics

-N: Display network-related statistics

-P: Show process-related statistics

-R: Displays statistics related to IO requests

-S: Show swapped related statistics

--tcp

--udp

--unix

--raw

--socket

--ipc

--TOP-CPU: Show CPU-intensive processes

--top-io: Show most io-intensive processes

--top-mem: Show the most memory-intensive processes

--top-lantency: Show the process with the most delay


Kill command:

Sends a control signal to the process for process management

Show current system available signals:

# kill-l

# Man 7 signal

Common signals:

1) SIGHUP: No need to close the process and let it reread the configuration file

2) SIGINT: Abort the running process, equivalent to CTRL + C

9) SIGKILL: Kill the Running process

SIGTERM: Terminating a running process

) Sigcont

SIGSTOP)

How to specify the signal:

(1) Digital identification of the signal; 1, 2, 9

(2) Signal complete name; SIGHUP

(3) abbreviated name of the signal; HUP

Signal to process: kill [-signal] PID ...

Terminates all processes under "name": Killall [-signal] Program


Job Control for Linux

Front-end operation: Start with terminal and occupy terminal after startup

Background jobs: Can be started through the terminal, but after starting to run in the background (release terminal)

How do I get my job running in the background?

(1) Operations in operation: CTRL + Z

(2) Jobs not yet started: # COMMAND &

This type of job is sent to the background, but it is still relevant to the terminal; If you want to send to the background, peel off the relationship with the terminal:

# Nohup COMMAND &

View All jobs:

# jobs

Job Control:

# FG [[[%]job_num]: Bring the specified background job back to the foreground

# BG [[%]job_num]: Allow jobs sent to the background to continue running in the background

# Kill [%job_num]: terminates the specified job


Process Priority tuning:

Static priority: 100-139

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

Nice command:

Nice [OPTION] [COMMAND [ARG] ...]

Renice command:

Renice [-n] Priority pid ...

View:

PS Axo Pid,comm,ni

This article is from the "Ricky Technology Blog" blog, make sure to keep this source http://r1cky.blog.51cto.com/10646564/1773861

Linux process and Job management

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.