What does the process do (* ̄︶ ̄)

Basic concept of process

Program
Software that implements certain functions, stored in the disk in the form of files

Process
running program

Parent process
The first main process started when the program is running

Child process
related processes caused by the parent process

Learning content:
1. The basic concept of the process
2. View the process and understand the information of the process
3. End the process
4. Adjust the priority of the
process 5. Switch between the front and back of the process

Command to
view the process pstree View the process tree
-u Display the user to which the process belongs
-p Display PID
-a Display parameters

ps view process

ifconfig | head -2: View the virtual machine ip address

View the current status of the process The
main information includes: process user, PID, stat status, command command and other information
[root@zhendong yum.repos.d]# ps
PID TTY TIME CMD
58973 pts/1 00:00:00 bash
62002 pts/ 1 00:00:00 ps

TTY: terminal number (use the tty command to view the current terminal)
pts/0-b pseudo terminal, usually the command interface for remote login to the Linux server

Options (there will be differences between adding-and not adding)
a Display other terminal processes
u Display process information in the format of user, PID
x Display system processes, usually processes generated by booting
e Display process environment information
f Displayed by _ The parent-child relationship between processes
l or -l displays process information in long format
-o displays process information in a custom format

Commonly used combinations
ps aux

USER: user name
PID: process number
1 process systemd, which is the parent process of all other processes, (ancestor)
%CPU CPU usage
%MEM memory usage
VSZ virtual memory
RSS actual memory
TTY terminal information
STAT status information
START Starting the process Time
TIME
The command of the running time COMMAND process

stat status
R running running status, the process being processed by the CPU
S sleeping Sleeping status, temporarily not running, hanging in the background, usually system service or network service
Z zombie zombie status (there is no process that exits normally)
T stopped paused status (hanging Status, not occupying CPU)
X dead process
<high ​​priority
N low priority
s (lower case) including child processes

  •   	位于后台的进程组
    

l Multiple child processes

ps -l

F process permission
4 means that the process is root permission
S process status
UID process user UID
PID process
PPID ParentPID, parent process ID
C CPU usage
PRI process priority
NI NICE value
ADDR_SZ WCHAN memory related
TTY terminal information
TIME running time
CMD Process name

ps -ef | more: add | more to add pipes and paging, so that the screen will not be occupied

top View process status dynamically The
second line
total is the total number of processes
running the number of running processes
sleeping The number of sleeping processes
stopped The number of stopped processes
zombie The number of zombie processes

The third line
%CPU
us(user space) Percentage of CPU occupied by user space
sy(system) CPU occupied by system kernel
ni(nice) CPU
id(idle) space occupied by the modified nice value CPU
wa(wait) Waiting for IO to be occupied CPU percentage
hi(hardware interrupt) CPU occupied by hard interrupt (hardware interrupt)
si(software interrupt) CPU occupied by soft interrupt (software interrupt)
st(stolen) CPU stolen, such as VMware

The fourth line
total total memory
free free memory
used used memory
buff/cache buffer/cache

The sixth line
PID process number
USER user
PR priority Priority
NI NICE value
VIRT virtual memory
RES resident memory
SHR shared memory
S status
%CPU CPU usage
%MEM memory usage
TIME+ running time
COMMAND process name

What key
q can be used during top execution to exit
? Display all available buttons
P Sort by CPU usage
M Sort by memory usage
N Sort by PID
T Sort by CPU usage time
W Save the current settings to /root/.toprc
d Modify the refresh interval (default 3 seconds)
z Display color The information
c display the complete command
f set the display field, sort field
R switch ascending order, descending order

Option
-d followed by the number of seconds
-b Execute top in batches
-n Used in conjunction with -b, specify the output of executing top several times
-p Observe the process of the specified PID
-u View the user's process

End process
kill

The essence of kill is to signal the process.
Commonly used signals:
9 Forced end
19 Pause
18 Continue
15 Normal exit
1 Reload
2 Forced interruption

To use kill, you must know the PID of the process

View the process PID
pidof Find the PID of the specified name
Example: pidof vim

ps -C keyword (precise search)
example: ps -C vim
pgrep -l keyword (fuzzy search)
example:
pgrep -l vi
or
ps -ef | grep vim

Kill process
kill -9 PID

View the list of signals kill -l
9 SIGKILL Force end
19 SIGSTOP Pause CTRL+Z
18 SIGCONT Continue
15 SIGTRM Normal exit CTRL+D
1 SIGHUP Reload
2 SIGINT Force interrupt CTRL+C

Force kill process
kill -9 PID

Pause the process
kill -19 PID
kill -stop PID

Activate the process
kill -18 PID
kill -cont PID

pkill
controls the process
pkill -9 vim according to the name of the process

According to user control process
pkill -9 -u username

According to the terminal control process
pkill -9 -t pts/2

killall kill all processes related to the
keyword killall -9 keyword

Three shortcut keys
CTRL+C to forcibly interrupt the foreground process kill -2
CTRL+D to exit the foreground process normally kill -15
CTRL+Z to suspend the process and suspend it kill -19

The operation mode of the process is
interactive. After
executing the command, human operation is required, which will occupy the command terminal:
for example: vim, man, passwd


After executing the command non-interactively , no human operation is required, and the command terminal is not occupied.
For example:
ls date pwd cal passwd –stdin

Switching between the front and back of the
process When starting the process, add & at the end of the command to make the command run in the background.
Example: the ping command will occupy the command prompt

Add & at the end to run in the background and not occupy the command prompt.
For example:
ping qq.com >> ping.log &
tail -f ping.log

Put the running process in the foreground to the background
ctrl+z

Display the pending tasks in the background
jobs
[root@zhendong 20200717]# jobs
[1]- Running ping 163.com >> ~/ping.log & (wd: /etc/yum.repos.d)
[2]+ Stopped vim haha

1 work number, the larger the work number, the newest open

  • Current process

The background task is returned to the foreground
fg job number

Process scheduling
Linux uses the CFS algorithm (complete fair scheduling)
. The lower the PRI value, the higher the program priority. The
PRI value cannot be modified directly, but the NICE value can be modified.

PRI(new)=PRI(old)+NICE

NICE value range: -20~19

Specify the NICE value
nice -n NICE value process name when starting the program

Modify the NICE value of an existing process
renice NICE value PID
Find file search command
grep: query keywords in the file (regular)
Find: find files in the specified directory

find path option action
find query path query condition condition related parameter processing query result

[root @ ops14 ~] # find ./ -name heihei -print
./20200713/heihei
./heihei

Note: If you do not specify a path, the file in the current directory is searched by default, and the search is recursive

Query conditions The
conditions can be file name, file size, file type, file permission, ownership, etc. The
default is to find all files in the specified directory

Search according to the file name
-name "file name": strictly case sensitive
-iname "file name": case insensitive

[root@ops14 ~]# find ./ -name heihei
./20200713/heihei
./heihei
[root@ops14 ~]# find ./ -iname heihei
./20200713/heihei
./heihei
./HEIHEI

According to the owner, group search
-user username: search for files belonging to the specified user
-group group name: search for files belonging to the specified user group

-uid UID: find files belonging to the specified UID
-gid GID: find files belonging to the specified GID

-nouser finds files that have no owner
-nogroup finds files that do not belong to a group

Search according to the type of
file -type file type
f file ordinary file (-)
d directory directory
c char dev character device
l (lowercase L) symbolic link
p pipe pipe
s sockt socket

例子:
find ./ -type f
find ./ -type d

Search according to the size of the file
-size [bkMG]
+3G is greater than 3G -3G is
less than 3G
3G is equal to 3G

Example:
find ./ -size +1k

Find
min minute minutes
time days by timestamp

Access time
amin
atime

Modification time (modify time file content is modified)
mmin
mtime

Change time (change time change permission chmod or change owner chown)
cmin
ctime

find / -atime 2 #Query the files that were accessed 2 days ago on the day
+ 2 Query the files that were accessed 2 days ago
-2 Query the files that were accessed within 2 days

Exercise:
1. Find files in the /tmp directory whose modification time is the day before
find /tmp -mtime 2
2. Find files in the /tmp directory whose modification time is the day before or earlier
find /tmp -mitme +2
3. Find the /tmp directory Files whose file attributes have been modified within the next week
find /tmp -ctime -7

Find
-perm permissions by file UGO permissions

Example:
find ./ -perm 644
rw-r—r—

Multi-condition search
condition 1 -and condition 2 logical AND -and == -a
condition 1 -or condition 2 logical OR -or == -o
! Conditional logic is not -not ==!

Example: Find files in the current directory that do not belong to the root user and whose file name is not file1.
find ./ -not -user root -and -not -name file1
or
find ./! -User root -a! -Name file1

Action (processing query results),
-print: default processing, print to the screen
-ls: similar to ls -l
-delete the query results to delete the files found

Exercise:
1. Find
files in the current directory that do not belong to the root user find ./ -not -user root
2. Find files in the current directory that do not belong to the root user and whose permissions (-perm) are 755
find ./ -not -user root -and -perm 755
3. Find ordinary files larger than 1M in the /etc/ directory (f)
find /etc -size +1M -and -type f
Find files in the current directory whose names start with a and end with c (a* c)

Guess you like

Origin blog.csdn.net/weixin_51014063/article/details/108739039