About nixCraft

Topics

Linux Manipulating real-time attributes of a process

Posted by Vivek Gite [Last updated: May 18, 2006]

Last time I wrote about how-to set or retrieve the CPU affinity of a running process given its PID or to launch a new COMMAND with a given CPU affinity.

If you are looking to sets or retrieves the real-time scheduling attributes of an existing PID or want to runs COMMAND with the given attributes then I recommend to use chrt command.

nice command run a program with modified scheduling priority however chrt is much more than nice command. chrt allows to set your scheduling policy as well as priority.
Currently, the following three scheduling policies are supported under Linux:

But what is scheduler?

The scheduler is the Linux kernel part that decides which runnable process will be executed by the CPU next. As I said earlier Linux offers three scheduling policies. One is for normal process and can be changes using nice or chrt command (or use system calls under C).

Discussion related to Linux scheduler and policies are beyond the scope of this post but I recommend following two textbooks for in-depth understanding of this topic:

  1. Programming for the real world - POSIX.4 by Bill O. Gallmeister, O'Reilly & Associates, Inc.
  2. Understanding the Linux Kernel, Second Edition by Daniel P. Bovet, Marco Cesati, O'Reilly & Associates, Inc.

Let us get back to chrt command. You can retrieve the real-time attributes of an existing task/pid with following command:

$ chrt -p 1

Output:

pid 1's current scheduling policy: SCHED_OTHER
pid 1's current scheduling priority: 0

Set process (PID 5124) to 5 priority: remember priority range from -20 (most favorable scheduling) to 19 (least favorable):

$ chrt -p 5 5124

You can retrieve minimum and maximum valid priorities with following command:

$ chrt -m

Output:

SCHED_FIFO min/max priority     : 1/99
SCHED_RR min/max priority       : 1/99
SCHED_OTHER min/max priority    : 0/0

Set scheduling policy to SCHED_RR:

$ chrt -p -r 5124

Where:

See also:

E-mail this to a Friend    Printable Version

Linux Powered Asus EEE Laptop PC From $299

You may also be interested in other helpful articles:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.