The Linux system is a multi-user and multi task system. When the biological software is running, it should be able to view the running status and monitor the running status of the software in real time, such as CPU memory usage. When there are errors in the operation, it should be able to kill the task in time and whether the front and back-end switching of the task is suspended.
Advance preview of current order:
top press "q" to exit View system operation status top -b press "Ctrl +C" to exit top -c top -u "yourname" htop htop View system operation status kill -9 "process number" Kill process passwd change your password Change Password sleep dormancy fg forehead Background program bg background Foreground program jobs View Daemons nohup Do not suspend the running program. The program continues to run after closing the login window disown Forget to use nohup After that, the background task is converted to nohup
1 view process
Process view can be used
Top and ps commands, where top can view dynamically and ps can view static results.
There are many processes running all the time in Linux system. If we can manage them reasonably, we can optimize the performance of the system. There are five common process states in Linux system, namely, running, interrupt, non interrupt, dead and stop. Their respective meanings are as follows.
R(Run): the process is running or waiting in the run queue. S(Interrupt): the process is in sleep. When a condition is formed or a signal is received, it will leave the state. D(Non interruptible): the process does not respond to the system asynchronous signal, even if it is used kill The command cannot interrupt it. Z(Dead): the process has terminated, but the process descriptor still exists, Until the parent process calls wait4()Release the process after the system function. T(Stop): the process stops running after receiving the stop signal.
Commands: top
top can dynamically display the usage of system processes, similar to the task manager of windows system. It can display the relevant information of the process being executed by the current system, including process ID, memory utilization, CPU utilization, etc.
top #press "q" to exit to view the system operation status top -b # press "Ctrl +C" to exit top -c top -u "yourname"
Line 1: system time, running time, number of login terminals and system load (the three values are the average values within 1 minute, 5 minutes and 15 minutes respectively. The smaller the value, the lower the load).
Line 2: total number of processes, running processes, sleeping processes, stopped processes and dead processes.
Line 3: percentage of resources occupied by users, percentage of resources occupied by system kernel, percentage of process resources whose priority has been changed, percentage of idle resources, etc. The data is CPU data and displayed in percentage format. For example, "99.9" means that 99.9% of CPU processor resources are idle.
Line 4: total physical memory, free memory, memory usage, memory used as kernel cache.
Line 5: total virtual memory, virtual memory free, virtual memory usage, and memory that has been loaded in advance.
Detailed explanation of top command results
content | interpretation |
---|---|
USER | Owner of the process |
PID | Process ID number |
%CPU | Arithmetic unit occupancy |
%MEM | Memory usage |
VSZ | Virtual memory usage in KB |
RSS | Amount of fixed memory occupied (in KB) |
TTY | Terminal |
STAT | Process status |
START | Start time |
TIME | Actual CPU usage time |
---|---|
COMMAND | Command name and parameters |
Command: ps: process status
ps is also a system process management tool. Different from top, top can be displayed dynamically, while ps is a static display, which is a snapshot at a certain time. The advantage of static display is that it is convenient for other programs to capture and process the results.
ps -aux - Display process information, including terminal free( x) ps -ef Displays all process information, along with the command line ps -aux --sort -pcpu | less according to CPU Use to sort in ascending order ps -aux --sort -pmem | less Sort in ascending order based on memory usage ps -aux --sort -pcpu,+pmem | head -n 10 consume CPU And memory top ten users a Show all processes -a Display all programs under the same terminal e Show environment variables f Show relationships between processes -H Display tree structure r Displays the program of the current terminal T Displays all programs of the current terminal -au Show more detailed information -aux Displays all trips that include other users -u Specify all processes for the user
2 front and background switching
& #Put command line tasks in the background sleep #Sleep for a certain time jobs # View Daemons fg #forehead switch to daemon bg #background switch to foreground program ctrl+z #Suspend task ctrl+c #Terminate task
Case:
#1. Running in the background for 200 seconds sleep 200 & sleep 300 & #2 jobs viewing tasks jobs #3 task 1 switch to the foreground fg 1 #4 switch to the background ctrl+z Suspension; bg 1;Switch to background operation; #5 task 2 switch to the front desk and kill bg 2 ctrl+c
3 task management
3.1 nohup non pending
The full name of the nohup command is "no hang up". This command can run the program by ignoring the hang up signal, and the output information of the running program will not be displayed to the terminal.
Whether or not the output of the nohup command is redirected to the terminal, the output will be attached to the nohup. In the current directory Out file. If the current directory is nohup The out file is not writable, and the output is redirected to $home / nohup Out file. If no file can be created or opened for append, the command specified by the command parameter is not callable. If the standard error is a terminal, all outputs written to the standard error by the specified command are redirected to the same file descriptor as standard output.
nohup sh scripts.sh &
3.2 switch to non off disown
The disown command can remove all jobs from the job list of the current shell, or remove one or more specified jobs; Running jobs can also be removed; You can also mark jobs so that they do not end after the current shell exits.
This command can be executed only when the set option monitor is on; View job control status: enter set o to view the monitor line; Execute set o monitor or set m to turn on this option. disown command this command is a bash built-in command. Please check the help command for relevant help information.
Common parameters:
-h Tag each job identifier, these jobs will not be shell Received sighup Signal received sighup signal -a Remove all jobs -r Remove running jobs
3.3 kill mission
The function of kill is to kill the process. The kill command can send the specified signal to the corresponding process or work. The default signal used by the kill command is 15, which is used to end a process or work. If a process or job ignores this signal, signal 9 can be used to force the process or job to be killed. Use kill l to view all signal values.
To kill a task with kill, first obtain the ID number of the task, which can be obtained through the top or ps command. For example, there is a sleep process with a pid number of 12000; kill 9 by force.
kill -9 12000
4 screen
Screen is a full screen window manager that can multiplex a physical terminal between multiple processes. There is the concept of session in screen. Users can create multiple screen windows in a session. In each screen window, it is like operating a real t elnet/SSH connection window. That is, after we log in to the Linux shell, run the screen command to open a new window, and the next task will run in the screen, so that even if the line is disconnected, the task will still exist. Similar to screen is the tmux command.
4.1 option parameters
$ screen --help Use: screen [-opts] [cmd [args]] or: screen -r [host.tty] Options:-A : Adjust all windows to the current terminal size. -d : The specified screen The job is offline. -h : Specifies the number of buffer rows for the window. -m : Even if you are currently in the job screen Job, still force the creation of a new screen Homework. -r: Restore offline screen Homework. -R : Try to resume an offline job first. If an offline job cannot be found, a new one is created screen Homework. -s: Specifies the to execute when creating a new window shell. -S: appoint screen The name of the job. -v : Displays version information. -x: Restore previously offline screen Homework. -ls: Show all current screen Homework. -wipe : Check all current screen Jobs and delete those that are no longer available screen Homework.
4.2 shortcut keys
You need to frequently use shortcut keys to use screen. The most commonly used shortcut is ctrl+a. some of the most commonly used shortcuts are listed below:
ctrl + a,d #Temporarily leave the current session ctrl + a,c #Create a sub session in the current screen session ctrl + a,w #Sub session list ctrl + a,p #Previous sub session ctrl + a,n #Next sub session ctrl + a,0-9 #Switch between the 0th window and the 9th sub session
4.3 use cases
A case of continuous downloading of biological data using screen
#1 create a new session named wget screen -S wget # 2 run command wget -c ftp://ftp.ncbi.nlm.nih.gov/blast/db/FASTA/swissprot.gz # 3 press ctrl+a and then the letter d to exit the session. The task is still running $ screen -S wget [detached from 283349.wget] # 4 screen -ls view task $ screen -ls There is a screen on: 283349.wget (Detached) 1 Socket in /var/run/screen/S-wangtong. #5 re enter the wget terminal and the task is running $ screen -r wget # 6. Close the session task. If you use exit in the session, you will exit the session and close the session, or press ctrl+a, k # screen ls view session $ screen -r wget [screen is terminating]