Linux tutorial-Process Scheduling

Source: Internet
Author: User
Article Title: Linux tutorial-Process Scheduling. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Kill command
  
When a foreground process needs to be interrupted, the 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 ends a 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, kill (9) signals may be used, and the signal cannot be captured.
  
The syntax format of the kill command is very simple. There are two methods:
  
Kill [-s Signal |-p] [-a] process number...
  
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.
  
Kill command usage
  
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.
  
Control Multiple Process commands
  
Linux allows users to run multiple processes at the same time, and allows users or system administrators to control running processes.
  
Nohup command
  
Theoretically, when we exit the Linux system, all the programs 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. out file (you can also use output redirection 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) users can only use the renice command for all their 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.
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.