101 3.6 modify process execution priorities

8
Junior Level Linux Certification

description

 

Transcript of 101 3.6 modify process execution priorities

Page 1: 101 3.6 modify process execution priorities

Junior Level Linux Certification

Page 2: 101 3.6 modify process execution priorities

Exam Objectives

Key Knowledge Areas

Know the default priority of a job that is created. Run a program with higher or lower priority than the default.. Change the priority of a running process.

Objective 3: GNU and Unix Commands

Modify process execution priorities Weight: 2

Terms and Utilities

nice ps renice top

2

Page 3: 101 3.6 modify process execution priorities

Modify process execution priorities

In Linux kernel, the scheduler is responsible for deciding which process is going to occupy the CPU's attention for the next millisecond.

One of the factors for making this decision is the priority or niceness of the process.

Process priority

3

1. Using nice you can change the niceness of new processes.

2. Using renice you can change execution priorities of running processes.

Page 4: 101 3.6 modify process execution priorities

Modify process execution priorities

nice - To change the priority of a process that is startedYou make it behave more nicely so it does not monopolise the CPU

Using nice

4

Niceness values range from: 20 (very nice) to 20 (not at all nice, quite important).-n switch specifies just how nice the process should be

• nice -n 15 process – start the process with a niceness of 15• nice -15 process – start the process with a niceness of 15• nice -n -15 process – start the process with a niceness of 15(higher priority)

The niceness of a process is inherited by the processes it creates. If the login sequence for a user sets the niceness of that user's processes, all processes run by the user are also nice.

Page 5: 101 3.6 modify process execution priorities

Modify process execution priorities

renice - used to set the priority of processes that are already running

Using renice

5

renice can zap specific processes or the processes owned by a user or a group.

• renice +1 -p 14292 – make process 14292 just a little nicer• renice +2 -u jack – make all of Jack's processes two notches nicer.• renice +3 -g users – make the processes whose group is “users” three notches nicer.

1. Users can only increase the niceness of their own processes.

2. Root can increase or decrease the niceness of any process.

3. If a process's niceness is 20, then it will only run when nothing else wants to.

Page 6: 101 3.6 modify process execution priorities

Modify process execution priorities

ps (process status) reports niceness of processes in the column STAT If process has any degree of niceness, the status column includes N.

ps and niceness

6

ps can be convinced to display the niceness of each process – but you wouldn't want to do this. (It's probably not in exam).

jack@foo:~> ps xPID TTY STAT TIME COMMAND2461 ? SN 0:00 /usr/sbin/sshd2463 pts/1 SN 0:00 -bash2510 pts/1 RN 0:00 ps x

Ex:

Ex:

george@foo:~> ps -eo pid,nice,user,args --sort=user | headPID NI USER COMMAND2636 10 george /usr/sbin/sshd2638 10 george -bash2663 10 george ps -eo pid,nice,user,args --sort=user2664 10 george head1196 0 at /usr/sbin/atd589 0 bin /sbin/portmap21330 10 michael /bin/sh /usr/X11R6/bin/kde21380 10 michael kdeinit: Running...21383 10 michael kdeinit: dcopserver --nosid

Page 7: 101 3.6 modify process execution priorities

Modify process execution priorities

top - shows the top processes on computer. Those that use all the resources top runs in console, and displays summary info at the top and a sorted list of processes.

ps and niceness

7

Ex:

Page 8: 101 3.6 modify process execution priorities

Fim de sessão

8