Linux Manipulating Real-time Attributes Of A Process

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. The chrt command allows to set your scheduling policy as well as priority. Currently, the following three scheduling policies are supported under Linux:

  • SCHED_FIFO: First In-First Out scheduling
  • SCHED_RR: Round Robin scheduling
  • SCHED_OTHER: Default Linux time-sharing scheduling

But what is a 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 blog post but, I recommend the 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.


You can retrieve the real-time attributes of an existing task/pid with the following command:
$ chrt -p 1

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), run:
$ chrt -p 5 5124
You can retrieve minimum and maximum valid priorities with the following command:
$ chrt -m
Sample outputs:

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, enter:
$ chrt -p -r 5124

  • -f: Set scheduling policy to SCHED_FIFO
  • -o: Set scheduling policy to SCHED_OTHER
  • -r: Set scheduling policy to SCHED_RR
  • -p: Operate on an existing PID and do not launch a new tas
See also:
  • man page chrt(1)
  • Please note that chrt command may be more useful if you are using real time Linux kernel.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • Amr El-Sharnoby Dec 14, 2009 @ 16:29

    -o: Set scheduling policy to SCHED_FIFO
    should be
    -o: Set scheduling policy to SCHED_OTHER

    • Santa Oct 23, 2012 @ 17:31

      You are right Amr, but nobody has changed it for almost 3 years ;).

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum