When learning about Linux processes, you may encounter the same problem. Here we briefly summarize the methods for Linux Process kill commands and Linux to control multiple commands, I would like to share it with you here, hoping to help you .......
Linux kill command
When a foreground process needs to be interrupted, the <Ctrl + c> key combination is usually used. However, a background process may not be able to solve the problem, in this case, you must turn to the kill command. This command can terminate background processes. There are many reasons for terminating the background process, maybe the process takes too much CPU time, or the process has crashed. In short, this situation often occurs. The kill command in a Linux Process ends the process by sending a specified signal to the process. If no sending signal is specified, the default value is the TERM signal. The TERM signal terminates all processes that cannot capture the signal. As for the processes that can capture the signal, kill9 may be used.) The signal cannot be captured.
The Linux kill command is simple. There are two methods:
1. kill [-s Signal |-p] [-a] process number...
2. kill-l [Signal]
◆-S specifies the signal to be sent. It can be either a signal name or a number.
◆-P specifies that the kill command only displays the pid of the process and does not actually send the end signal.
◆-L display the signal name list, which can also be found in the/usr/include/linux/signal. h file.
Linux kill command
The following describes how to use this command.
[Example 24] When executing a find command, the process is terminated for a long time.
First, you should use the ps command to view the PID of the Process, type ps, and display as follows:
PID TTY TIME COMMAND
285 1 00:00:00-bash
287 3 00:00:00-bash
289 5 00:00:00/sbin/mingetty tty5
290 6 00:00:00/sbin/mingetty tty6
312 3 00:00:00 telnet bbs3
341 4 00:00:00/sbin/mingetty tty4
345 1 00:00:00 find/-name foxy.jpg
348 1 00:00:00 ps
We can see that the PID corresponding to the process is 345. Now we use the kill command to terminate the process. Type:
# Killed 345
Run the ps command to check whether the find process has been killed.
[Example 25] Kill process 11721
# Ps PID TTY TIME COMMAND
11668 p1 00:00:00-tcsh
11721 p1 00:00:00 cat
11737 p1 00:00:00 ps
# Killed 11721
[1] Terminated cat
#
Sometimes, a process is suspended or idle, but cannot be killed by using the kill command. At this time, you must send the signal 9 and forcibly disable the process. Of course, this "brutal" method may lead to errors such as opening files or data loss. Therefore, do not use the force termination method. If the signal 9 does not respond, I am afraid it is only necessary to restart the computer.
Linux allows you to run multiple processes at the same time and allows you or the system administrator to control running processes.
Nohup command
Theoretically, when we exit the Linux system, all the programs in all Linux processes will be terminated, including those background programs. But sometimes, for example, if you are editing a very long program, but you need to exit the system after work or after something happens, you do not want the system to end the program that you have edited for so long, if you want to exit the system, the program continues to run. In this case, we can use the nohup command to run the process after the user exits.
Generally, these processes are all executed in the background, and the results will be written to the nohup under the user's own directory. you can also use output redirection in the out file to output it to a specific file ).
[Example 26] $ nohup sort sales. dat &
This command tells the sort command to ignore that the user has exited the system. It should always run until the process is completed. This method can be used to start a process that needs to run for several days or even weeks, and the user does not need to log on when it is running.
The nohup Command sends all output and error messages of a command to the nohup. out file. If the output is redirected, only the error information is stored in the nohup. out file.
Renice command
The renice command allows you to modify the priority of a running process. The renice command can be used to adjust its priority when executing the command. The format is as follows:
$ Renice-number PID
The parameter number has the same meaning as the number of the nice command.
Note:
1) You can only use the renice command for all your processes.
2) the root user can use the renice command on any process.
3) Only the root user can improve the priority of the process.
Questions
1. What is a linux Process? What is the difference between a process and a job?
2. What are the methods for starting a process?
3. What are the essential differences between at commands and batch commands?
4. When will the cron command be executed? How can I change the execution status?
5. What are foreground and background tasks? How do I suspend the current foreground job? What should I do if I want to resume its operation?
6. What are the process viewing commands? What are their differences?
7. How to interrupt a background process?
8. How can a process still be executed when the user exits the Linux system?
9. How to modify the priority of a job?
10. Write and verify the command pipeline line that completes the following functions:
1) displays the number of login names in the current system.
2) display the number of processes in the current system.
11. describe the functions of the following MPs queue lines:
1) df-a | wc-l
2) who | wc-
- Linux disk partitioning
- Linux file commands
- Describes the entire process of Linux User Management
- DIY Linux cluster machines in file cabinets
- Linux memory management-discontinuous physical address allocation (vmalloc)