RSS Subscription
Linux Howtos & Tutorials

Enter your email:

Delivered by


NOTE:New tutorials are from LinuxCareer.com

Poll

Do you own or wish to have iPhone?
 


Linux eBooks FREE Download
A guide to programming Linux kernel modules
Introduction to Linux - A Hands on Guide
A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

Linux: The Hacking Solution (v.3.0)

SQLite 3 with PHP Essential Training – Free Video Training Tutorials

This guide will introduce you to the world of GNU/Linux

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)

Advanced Bash-Scripting Guide

Set up, maintain, and secure a small office email server

Partner Linux Sites:
How-To.LinuxCareer.com
Jobs.LinuxCareer.com
TuxMachines
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
All For Linux

Change the priorities of linux processes with nice and renice

Every process running on the linux system has a default priourity assined which tells the the system how much proccessing power should be deticated to each particular process. It is possible to change this priority value with nice or renice command. Here is a small example: Let's say that we have a very simple bash script which prints date and time to the file 1000 times.

#!/bin/bash
for i in $(seq 1 1000); do date >> date.txt;sleep 1; done

Save this script and make it executable with chmod command. Execute the script:

$ nice -n 00 ./date &

By executing a ./date script with nice -19 command we gave the date.sh very high priority as the priority range is from -20 ( higest ) to 19 ( lowest ). to confirm the priority run ps -l command from the same terminal.

F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S  1000  3670  2940  0  80   0 -  1196 -      pts/2    00:00:00 bash
0 S  1000  6665  3670  0  90  10 -  1111 -      pts/2    00:00:00 date.sh
0 S  1000  6697  6665  0  90  10 -   754 -      pts/2    00:00:00 sleep

as you can see date command and sleep command has same priority 10. However sleep running inside a date.sh is a child process of date.sh and date.sh is a parent process of sleep. At this stage we can try to change the priority to some othre value with renice command and with use a PID ( Proccess Identification Number ):

$ renice 15 -p 6655
6665: old priority 10, new priority 15

The command above will change nice value from 10 to 15. to confirm priority value:

F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S  1000  3670  2940  0  80   0 -  1198 -      pts/2    00:00:00 bash
0 S  1000  6665  3670  0  95  15 -  1113 -      pts/2    00:00:00 date.sh
0 S  1000  7109  6665  0  95  15 -   754 -      pts/2    00:00:00 sleep

NOTE: With a non-super user account you can change priorities only for the processes you own, assign priorities only in range of 0 - 19 and you can only increase a nice value. root user can change any process to any priority nice value. Another way to change priorit values is to use top command and r key.

Share this linux post:

Submit Change the priorities of linux processes with nice and renice in Delicious Submit Change the priorities of linux processes with nice and renice in Digg Submit Change the priorities of linux processes with nice and renice in FaceBook Submit Change the priorities of linux processes with nice and renice in Google Bookmarks Submit Change the priorities of linux processes with nice and renice in Stumbleupon Submit Change the priorities of linux processes with nice and renice in Technorati Submit Change the priorities of linux processes with nice and renice in Twitter
 
Comments for this page are closed !!!
Please visit our new Linux Forum for additional help or discussion.


Linux eBooks FREE Download