Linux Foundation Process Management priorities

Source: Internet
Author: User
Tags cpu usage

one, process priorityLinux process scheduling and multitasking

Each CPU (or CPU core) can handle only one process at a time, and with time slice technology, the number of processes (and threads) that Linux actually can run exceeds the number of CPUs and cores actually available. The Linux kernel process scheduler quickly switches multiple processes on the CPU core, giving the user the impression that multiple processes are running at the same time;

Relative priority Nice

Because not every process is as important as other processes, you can tell the process scheduler to use different scheduling policies for different processes, and most processes running on a regular system use a scheduling policy of Sched_other (also known as Sched_normal). But there are other scheduling strategies that are used for different purposes.

The relative priority of the process running by the Sched_other scheduling policy becomes the nice value of the process, which can have 40 different levels of nice values;

The higher the Nice value: the lower the priority, for example +19, which makes it easier for the process to cede CPU usage to other processes;

The lower the Nice value: the higher the priority, for example, 20, the process is less inclined to yield the CPU;

view the nice level of a process

1. Use top to view the nice level

NI: actual nice level

PR: Show nice level as map to larger priority queue, 20 map to 0,+19 map to 39

2. Use PS to view the nice level

[[Email protected]1~]#PSAxo Pid,command, Nice--Sort=- NicePID COMMAND NI1/sbin/init0    the/sbin/mingetty Console0  375Rpcbind0  424Dbus-daemon--system0  814 Login--Root0  816/sbin/mingetty/dev/tty20 9106/usr/bin/python/usr/bin/ss019827sshd: [Email protected]/3              0
[[Email protected]1~]#PSAxo Pid,command, Nice, CLS--Sort=- NicePID COMMAND NI CLS1/sbin/init0TS the/sbin/mingetty Console0TS375Rpcbind0TS424Dbus-daemon--system0TS814 Login--Root0TS816/sbin/mingetty/dev/tty20TS9106/usr/bin/python/usr/bin/ss0TS19827sshd: [Email protected]/3              0TS19829-bash0TS21228/sbin/dhclient-h Lcq-cento0TS29860sshd: [Email protected]/5              0TS29869SSHD: [Email protected]0Ts

TS indicates that the process uses a scheduling policy of Sched_other

Start a process with a different nice level

When you start a process, you typically inherit the nice level of the parent process, which defaults to 0.

[[Email protected]1~]# Nice-N5 Sleep  the&[1]30221[[Email protected]-1~]#PSAxo Command,pid, Nice|grep SleepSleep  the                  30221   5grep Sleep                  30249   0[[Email protected]-1~]#
[[Email protected]1~]# Nice-N- -service httpd start[[email protected]-1~]#PSAxo Pid,command, Nice, CLS |grephttpd11116/USR/SBIN/HTTPD- -TS11119/USR/SBIN/HTTPD- -TS11120/USR/SBIN/HTTPD- -TS11121/USR/SBIN/HTTPD- -TS11122/USR/SBIN/HTTPD- -TS11123/USR/SBIN/HTTPD- -TS11124/USR/SBIN/HTTPD- -TS11125/USR/SBIN/HTTPD- -TS11126/USR/SBIN/HTTPD- -Ts

change the nice level of an existing level process

1. Change the nice level with top

R Adjustment Process priority (Nice level) (-20 max)--------0------(19 min)

2. Change the nice level with the shell

ii. Operations Control Jobs

Job control is a command-line feature that allows a shell instance to run and manage multiple commands.

If there is no job control, the parent process fork () after a word process, will sleeping until the child process exits.

With job control, you can selectively pause, resume, and run commands asynchronously, allowing the shell to return to accept other commands while the child process is running.

Foreground,background,and contrlling Terminal

Foreground: The foreground process is a command running in the terminal, which is the control terminal of the process, the foreground process receives input and signals from the keyboard and allows reading from or writing to the terminal.

Background: The background process does not control the terminal, it does not require terminal interaction.

Example 1:
Sleep  &                        // Run the program (when), allowing it to perform sleep4000                            //^z in the background, Suspend (pause) The foreground program to the backstage [2]+  Stopped             sleep4000
[Email protected] ~]#PSAux |grep SleepRoot8895  0.0  0.0 100900   556pts/0S A: -   0:xx Sleep  theRoot8896  0.0  0.0 100900   556pts/0T A: -   0:xx Sleep 4000
[[email protected] ~]# jobs                                     // View background Jobs [1]-  Running                sleep3000 &[2]+ Stopped                sleep4000
[[email protected] ~]# bg%2                                // let job 2 run in the background [[email protected] ~]# FG%1                                / / Move Job 1 back to foreground  kill %1                                //kill 1, terminate PID 1 process
preview:
[[Email protected] ~]# (while doingdatesleep2done) &  // The process runs in the background, but the output is still in the current terminal  ~]# (while doesdatesleep2done) & >/dev/null &

& at the end of the command is the background character

Example 2: How to manage a remote host
SSH 10.18. 40.100  Yuminstall screen                        // first time [[email protected] ~]# screen-s Install_ Apache

Reconnect after the network is disconnected

[Email protected] ~]# screen-listthere is screens on:    28958. Install_nginx    (Detached)     29013 . Install_apache    (Detached) 2  in/var/run/screen/s-29013

Linux Foundation Process Management priorities

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.