1、 Process management

1.1 Process management

1.1.1 Introduction to the process

       A process is a program or command that is executing , Each process is a running entity , All have their own address space , And occupy certain system resources .

1.1.2 The role of process management

       Determine the health status of the server            top command

       View all processes in the system            ps Command and pstree command

       Kill process

1.2 Process view

1.2.1 View all processes in the system

       $ ps aux         View all processes in the system , Use BSD Operating system format    Common formats

       $ ps -le           View all processes in the system , Use Linux Standard command format


       USER     Which user generated the process

PID        Process ID Number

%CPU    The CPU % of resources , The higher the occupancy , The more resources the process consumes

%MEM   The percentage of physical memory used by the process , The higher the occupancy , The more resources the process consumes

VSZ        The size of virtual memory occupied by this process , Company KB

RSS        The size of the actual physical memory occupied by the process , Company KB

TTY        Which terminal is the process running on . among tty1-tty7 On behalf of local console terminal ,tty1-tty6 It's a local character interface terminal ,tty7 It's a graphic terminal .pts/0-255 On behalf of virtual terminal

       STAT      Process status . Common are :R function ;S sleep ;T stop it ;s Full man process ;+ In the background

START    The start time of the process

TIME      The process takes up CPU Operation time of , Note it's not system time

COMMAND  The name of the command that generated this process            important !!

1.2.2 View system health status

       $ top [ Options ]

              -d           Appoint top The command is updated every few seconds . The default is 3 second

       stay top Commands that can be executed in Xiao Hu mode of command :

? or h       Display help for interactive mode

P            With CPU Usage sort , This is the default

M           Sort by memory usage

N            With PID Sort

q            sign out top


       The first line of information is task queue information

       12:26:46                Current system time

       up 1 day,13:32    Running time of the system , This machine is running 1 God 13 Hours 32 minute

       2users                   Currently logged in 2 Users

       load average0.00,0.00,0.00             The system is before 1 minute ,5 minute ,15 Average load in minutes . Generally considered less than 1 when , Low load ; If it is greater than 1, The system has been overloaded .1 representative 1 A nuclear .

       The second line is process information

       Tasks:95total The total number of processes in the system

       1 running              Number of running processes

       94 sleeping            The process of sleep

       0 stopped               The process being stopped

       0 zombie               Zombie process . If not 0, Need to check the zombie process by hand .

       The third line of information is CPU Information

       Cpu(s): 0.1%us      User mode CPU percentage

       0.1%sy                  The system mode occupies CPU percentage

       0.0%ni                  Change the priority of the user process occupied by CPU Table Chalk

       99.7%id               Free CPU Of CPU percentage

       0.1%wa                 Waiting for input / Occupation of the output process CPU percentage

       0.0%hi                  Hard interrupt request service occupied CPU percentage

       0.1%si                  The soft interrupt request service occupies CPU percentage

       0.0%st                  st(Steal time) Percentage of virtual time . When there is a virtual machine , fictitious CPU Wait for the moment CPU Percent of time

       The fourth line is physical memory information

       Mem:625344k total     The total amount of physical memory , Company KB

       571504k used                The amount of physical memory that has been used

       53840k free                  The amount of free physical memory , We use virtual machines , All in all, only 628MB Memory , So only 53MB Free memory of

       65800k buffers              The amount of memory used as a buffer

       The fifth line of information is the exchange partition (swap) Information

       Swap : 524280k total        Swap partition ( Virtual memory ) The total size of

       0k used                               The size of the swap partition that has been used

       524280k free                       The size of the free swap partition

       409280k cached                   The size of the swap partition as the cache

1.2.3 View the process tree

       $ pstree -pu

              -p    Show progress PID

              -u    Show users of the process

1.3 Terminate the process

1.3.1 kill command

       $ kill -l          View available process signals


       1     SIGHUP        This signal causes the process to shut down immediately , Then reread the configuration file and restart

       2     SIGINT          Program termination signal , Used to terminate foreground process . Equivalent to output Ctrl+C Shortcut key

       8     SIGFPE         Occurs when a fatal arithmetic error occurs , Not only floating-point errors , It also includes overflow and divisor 0 And all the other arithmetic errors

       9     SIGKILL              Used to end the program immediately , This signal cannot be blocked 、 Handling and ignoring . Generally used to force the termination of a process

       14    SIGALRM      Clock timing signal , It's the actual time or clock time ,alarm The function uses the signal

       15    SIGTERM     Signal to end the process normally ,kill Default signal for command , Advantage if the process has gone wrong , This signal is unable to terminate the process normally , We will try SIGKILL The signal , That's the signal 9

       18    SIGCONT      This signal allows the suspended process to resume execution , This signal cannot be blocked

       19    SIGTOP         This signal can pause the foreground process , Equivalent to typing Ctrl+Z Shortcut key . This signal cannot be blocked


       $ kill -1 22654              Restart the process

       $ kill -9 22368              Force kill process

1.3.2 killall command

       $ killall [ Options ] [ The signal ] Process name             Kill process by process name

              -i     Interactive , Ask if you want to kill a process

              -I     Ignore the case of the process name

1.3.3 pkill command

       $ pkill [ Options ] [ The signal ] Process name                      Terminate program by process name

              -t Terminal number        Kick out the user according to the terminal number


       Kick out the user according to the terminal number

              $ w                       Use w Command to query the logged in users of this machine

              $ pkill -t -9 pts/1    Force to kill pts/1 Virtual terminal login process

2、 Work management

2.1 Put the city backstage

       tar -zcf etc.tar.gz /etc &

       $ top              stay top During command execution , Press down Ctrl+Z Shortcut key

2.2 Check the background work

       jobs -l

              -l     Show working PID

       notes :“+” The latest job put into the backstage by band number , It's also work response , Work restored by default .“-” The second from the bottom of the No. 1 band is put into the backstage

2.3 Resume the suspended work in the background to the foreground for execution

       $ fg % Work number

       Parameters :

              % Work number         % It can be omitted , But pay attention to the work number and PID The difference between

2.4 Resume the work suspended in the background to run in the background

       $ bg % Work number

       notes : The command that the backstage replies to execute , Can't interact with the front desk , Otherwise, it cannot be restored to the background .

3、 View system resources

3.1 vmstat Command monitoring system resources

       $ vmstat [ Refresh delay Refresh times ]

       for example

       $ vmstat 1 3

3.2 dmesg Kernel detection information at boot time

       $ dmesg

       for example

       $ dmesg | grep CPU

3.3 free Command to view the memory usage status

       $ free -bkmg

              -b    In bytes

-k    With KB In units of , Default is to KB Display in units

-m   With MB Display in units

-g    With GB Display in units


       The difference between caching and buffering

              Simply put, caching (cache) It's used to speed data from the hard disk “ Read ” Of , And the buffer (buffer) It's used to speed up data “ write in ” The hard disk .

3.4 see CPU Information

       $ cat /proc/cpuinfo

3.5 uptime command

       $ uptime         Display the startup time and average load of the system , That is to say top The first line of Ming Lin .w The command can also see this data

3.6 View system and kernel related information

       $ uname -ars

              -a    Check all relevant information of the system

-r     View kernel version

-s     Look at the kernel name

       Determine the number of digits in the current system

              $ file /bin/ls

       View the current Linux The hairstyle version of the system

              $ lsb_release -a

3.7 Lists the file information that the process opens or uses

       $ lsof [ Options ]                 Lists information about the files that the process calls or opens

              -c character string       List only files opened by processes that start with a string

              -u user name       List only the files opened by a user's process

              -p pid             List some PID The file opened by the process




4、 System timing task

4.1 crond Service management and access control

       $ service crond start

       $ chkconfig crond on

       You don't usually need to set it , Most machines are installed with this service and started by themselves

4.2 User crontab Set up

       $ crontab -elr

              -e    edit crontab Timing task

-l     Inquire about crontab Mission

-r     Delete all of the current user's crontab Mission


       $ crontab -e           Get into crontab Convenient interface , Will open vim Edit your work

              * * * * * Tasks performed

       The first 1 individual “*”         The first few minutes of an hour        0-59

       The first 2 individual “*”         The hours of the day            0-23

       The first 3 individual “*”         The day of the month            1-31

       The first 4 individual “*”         The month of the year               1-12

       The first 5 individual “*”         What day of the week               0-7(0 and 7 All represent Sunday )


       45 22 * * * command    Every day 22 spot 45 Sub executive order

       0 17 * * 1 command      Every week 1 Of 17 spot 0 Sub executive order

       0 5 1,15 * * command   Every month 1 Number and 15 The no. 5 spot 0 Sub executive order

       40 4 * * 1-5 command   Every week 1 By the end of the week 5 Of 4 spot 40 Sub executive order

       */10 4 * * * command   Every day at 4 spot , every other 10 One command per minute

       0 0 1,15 * 1 command   Every month 1 Number and 15 Number , Once a week 1 Of 0 spot 0 Sub executive order ( notes : It's better not to show up at the same time on the day and the day of the week , Because they define the sky , Very easy to )


       *     On behalf of any time . For example 1 individual “*” It means every minute of an hour

       ,    Represents a time of discontinuity . such as “0 8,12,16 * * * command ”, It means every day 8 spot 0 branch ,12 spot 0 branch ,16 spot 0 Every minute carries out an order

       -      Represents a continuous time range . such as “0 5 * * 1-6”, On behalf of... From Monday to Saturday 5 spot 0 Sub executive order

       */n   How often does the representative execute the order . such as “*/10 * * * * command ”, Represents every 10 One command per minute .


       give an example

       */5 * * * * /bin/echo “11” >> /tmp/test

       5 5 * * 2 /sbin/shutdown -r now

       0 5 1,10,15 * * /root/sh/autobak.sh                     Backup scripts

1、 Process management