Using renice and taskset to manage process priority and CPU affinity with Linux OEL 6.4

Using renice and taskset to manage process priority and CPU affinity with Linux OEL 6.4

Table of Contents

Overview

Process NICE priority values range from -20 to 19. ( see top NI column )
NI is the nice value, which is a user-space concept. PR is the process’s actual priority, as viewed by the Linux kernel.

For normal processes, the kernel priority is simply +20 from the nice value. Thus a process with the neutral nice value of zero has a kernel priority of 20. This offset-by-20 is done so that a process with a nice value of -20, the highest priority nice value, receives a kernel priority of zero. Lower numeric values equal higher scheduling priority.
For realtime processes, the kernel priority is the process’s real-time priority, but the PR column will simply print RT.

A process with the nice value of -20 is considered to be on top of the priority. And a process with nice value of 19 is considered to be low on the priority list.Using renice and taskset to manager a Linux process

 

Using renice and taskset to manage a Linux process

Display CPU Affinity for LGWR process and change CPU affinity to CPU 5

$ ps -elf | egrep 'NI|ora_lgwr' |  grep -v grep
F S UID        PID  PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
0 S oracle    5825     1  0  60 -20 - 394456 semtim 13:25 ?       00:00:24 ora_lgwr_grac41

$ taskset -pc 5 5825
pid 5825's current affinity list: 0-7
pid 5825's new affinity list: 5

Monitor CPU affinity with top 
# top -H -p 5825 [  --> Press f --> Press j to add CPU affinity col ]
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  P COMMAND                                                              
 5825 oracle    20   0 1540m  32m  28m S  0.0  0.8   0:24.62 5 oracle             
--> P shows the CPU affinity which is 5 !

Compile a load program and and set affinity to CPU 5 during program start 
$ cc sq.c -o sq -lm
$ taskset -c 5 sq
$ sp
PID: 15949

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  P COMMAND                                                              
15949 oracle    20   0  6544  312  244 R 73.7  0.0   1:50.17 5 sq                                                                   
 5825 oracle    20   0 1540m  32m  28m S  0.0  0.8   0:25.10 5 oracle     

Increase the priority of a process and monitor this process
# renice -15 15949

# top -H -p 15949 [  --> Press f --> Press j to add CPU affinity col ]
Cpu(s):  9.5%us,  3.1%sy,  0.0%ni, 87.2%id,  0.1%wa,  0.0%hi,  0.2%si,  0.0%st

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  P COMMAND                                                              
15949 oracle     5 -15  6544  308  244 R 70.9  0.0  38:43.36 5 sq                                                                   
 5825 oracle    20   0 1540m  33m  29m S  0.0  0.8   1:20.49 5 oracle
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Prosty skaner portów TCP w bash
Viewed 2961 times since Thu, May 24, 2018
Find All Large Files On A Linux System
Viewed 1860 times since Mon, Oct 29, 2018
Linux Audit The Linux security blog about Auditing, Hardening, and Compliance lynis
Viewed 1755 times since Thu, Jan 16, 2020
Linux / UNIX: DNS Lookup Command
Viewed 9342 times since Sun, Sep 30, 2018
WatchDog watchdog.sh script for checking server running
Viewed 5056 times since Tue, Jul 31, 2018
debian How to Upgrade Debian 8 Jessie to Debian 9 Stretch
Viewed 2065 times since Sun, Sep 23, 2018
RHEL: Route network packets to go out via the same interface they came in
Viewed 2665 times since Sat, Jun 2, 2018
SPRAWDZONA KONFIGURACJA RSYSLOG I LOGROTATE, JAKO ZEWNĘTRZNEGO SERWERA SYSLOG
Viewed 3474 times since Fri, Nov 30, 2018
RHEL: Adding a boot entry to GRUB/GRUB2 configuration
Viewed 4081 times since Sun, May 27, 2018
Top 20 OpenSSH Server Best Security Practices ssh linux aix
Viewed 5561 times since Fri, May 15, 2020