Last Updated : 23 Sep, 2024
'chrt' command in Linux is known for manipulating the real-time attributes of a process. It sets or retrieves the real-time scheduling attributes of an existing PID, or runs the command with the given attributes. 'chrt' can help optimize process management in a Linux system, especially for applications that require real-time performance.
Syntax$ chrt [options] priority command [argument ...]
$ chrt [options] -p [priority] pid
where,
Common Options with 'chrt' command Option DescriptionNote: The 'chrt' command typically requires root privileges to modify scheduling policies for existing processes.
-b, --batch
Sets the policy to SCHED_BATCH. -d, --deadline
Sets the policy to SCHED_DEADLINE. -f, --fifo
Sets the policy to SCHED_FIFO. -i, --idle
Sets the policy to SCHED_IDLE. -o, --other
Sets the policy to SCHED_OTHER (default time-sharing). -r, --rr
Sets the policy to SCHED_RR (default real-time policy). -p, --pid
Operates on an existing process with the specified pid. -a, --all-tasks
Operates on all tasks (threads) for a given pid. -m, --max
Displays the minimum and maximum valid priorities for the policies. -v, --verbose
Displays status information. -h, --help
Displays help information and exits. --version
Displays version information and exits Scheduling Options with 'chrt' Command
Here are some examples of how to use chrt to manage real-time scheduling:
1. To see the current scheduling policy:First we have to make a process. Let's take a example, Firefox is running and to find its's pid we run the following command:
$ pidof -s firefox
In my case the pid is 5794, here is the image
Now to retrieve the current scheduling policy and priority for the firefox process, use chrt in the following way:
$ chrt -p 57942. To change the scheduling policy to SCHED_FIFO:
From the above example, the scheduling policy of firefox process is set as SCHED_OTHER. Now to change the policy to SCHED_FIFO we can use the following command:
$ sudo chrt -f -p 57943. To change the scheduling policy SCHED_BATCH:
From the above example, the scheduling policy of the firefox process is set as SCHED_FIFO. Now to change the policy to SCHED_BATCH we can use the following command:
$ sudo chrt -b -p 57944. To see the maximum and minimum valid priorities:
This can be done using the -m command line option mentioned in the policy of chrt.
$ chrt -mConclusion
The 'chrt' command in Linux is a powerful tool for controlling the scheduling attributes of processes. By understanding how to use it effectively, you can optimize system performance for real-time tasks or background jobs, depending on your specific needs. 'chrt' allows you to fine-tune how these processes are scheduled, ensuring that critical tasks are prioritized appropriately while preventing less important tasks from consuming excessive system resources.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4