This article mainly explains Linux Process control commands , These commands are very common in work , The blogger will give specific examples and screenshots to explain

Pre knowledge :

1. Program and process concept :
program : Is a file that contains executable code , Stored on disk and other media , It belongs to static concept
process : When a program is loaded into memory by the operating system and allocated certain resources to it , This can be called a process , It belongs to dynamic concept
The following is the process state transition diagram :

View process :

1.  ps
English original meaning :report a snapshot of the current processes.( Reports a snapshot of the current process )
Function description :ps The command is used to display the instantaneous process information of the system , It can be displayed in user input ps System process and process related information during command
grammar :ps [options]
Common parameters :
-l: Long format output
-u: Displays processes in the order of user name and start time
-j: Display processes in task format
-f: Displays processes in a full list format
-a: Show all user processes ( Include other users )
-x: Show processes without control terminals
-r: Show running processes
example :
Usually we often use ps -aux To view the system and the processes of each user :

But what if we want to further filter the processes listed above , such as : I just want to see users as mr.s What about the whole process ?( Most commonly used in work )
ps -aux | grep mr.s

2. top
English original meaning :display Linux processes( display linux process )
Function description : Tools for dynamically monitoring system tasks , The output results are continuous ( similar Windows Task manager for )
grammar :top [options]
Common parameters :
-b: Run in batch mode , But cannot receive command line input
-c: Show command line , Not just the command name
-d N: Displays the interval between two refreshes , such as -d 5, Indicates that the interval between two refreshes is 5 second
-i: Disable the display of idle or zombie processes
-n NUM: Displays the number of updates , Then exit . such as -n 5, express top to update 5 Data exit
-p PID: Only the specified processes are monitored PID
-q: Refresh without any delay
-s: Safe mode operation
-S: Cumulative mode , Output total per process CPU,MEM Wait time
example :
top -d 5 ( appoint 5 Refresh every second )

  In this interface ,
Press u key , Enter the corresponding user name , You can view the running process of the user
Press k key , Enter the name of the corresponding running process PID, You can kill the process

Process control :

1. kill
English original meaning :terminate a process( terminate a process )
Function description : This command is used to send a message to a process ( adopt PID identification ) Send a signal , It is usually associated with ps and jobs Use with command
grammar :kill -signal pid...
signal The parameters are as follows :
1:SIGHUP, Start the terminated process
2:SIGINT, Equivalent to input ctrl+c, Interrupt the operation of a program
9:SIGKILL, Force interruption of a process
15:SIGTERM, End the process in the normal way
17:SIGSTOP, Equivalent to input ctrl+z, Pauses the progress of a process
example :
kill -9 1024( Forced killing PID by 1024 Process of )

2. killall
English original meaning :kill processes by name( Kill process by process name )
Function description : The instruction uses the process name to kill the process , Use this instruction to kill a group of processes with the same name
It and kill Differences between :kill Is to kill the designated PID Process of , However, you need to query the of the specified process PID, First use ps -aux | grep xxx
Found the process to kill PID, Pass again kill Command to kill , and killall The instruction combines the two processes into one
grammar :killall [options] name...
Common parameters :
-e,--exact: Exact matching of long names
-I, --ignore-case: Ignore case differences
-i, --interactive: Interactive kill process , Confirmation is required before killing
-l, --list: Print a list of all known signals
-q, --quiet: If no process is killed , No information is output
-r, --regexp: Use regular expressions to match the name of the process to be killed
-s, --signal: Replaces the default signal with the specified process number “SIGTERM”
-u, --user: Kill the process of the specified user
example :killall game( Kill process named game Process of )

3. nice
English original meaning :run a program with modified scheduling priority( Run the program with the modified scheduling priority )
Function description :nice The command allows you to run the program by increasing or decreasing the default priority
grammar :nice [OPTION] [COMMAND [ARG]...]
Adjustment range of priority :-20 ~ 19, The smaller the value, the higher the priority
if nice The command does not specify an adjustment value for priority , By default, it is added to the original priority 10
Common commands :
-n, --adjustment=N:add integer N to the niceness (default 10), Specifies the adjustment value of program running priority
example :
nice -n -5 myprogram& ( In the background at the normal running priority -5 Priority run myprogram )

4. renice
English original meaning :alter priority of running processes( Change the priority of running processes )
Function description : Change the priority of running processes
grammar :renice [-n] priority <pid>
Common parameters :
-n, --priority: Specifies the adjustment value of program running priority
example :
renice -5 777( Will be running PID by 777 The process priority of is changed to -5)

miscellaneous :

1. &
Function description : Put the process in the background to run
example :
cp -r /user/* test &( take /user Copy all subdirectories and files under the directory to test The working process under the directory is put into the background to run )

2. keyboard entry
ctrl + z: process was suspended
ctrl + c: Process termination ( Commonly used )

3. Process recovery
fg [n]: Will specify n The process resumes to the foreground and continues to run
bg [n]: Will specify n The process resumed running in the background
example :
Enter first man ls, Then press ctrl + z Suspend the process , Then pass jobs View suspended processes , Then pass bg
1, Put the suspended process in the background to continue running , Finally passed fg 1, Put the background process into the foreground to run

4. jobs
Function description : View suspended processes
grammar :jobs
example :jobs
 

 

Technology