sched_setscheduler() - Unix, Linux System Call

Unix - Home
Unix - Getting Started
Unix - File Management
Unix - Directories
Unix - File Permission
Unix - Environment
Unix - Basic Utilities
Unix - Pipes & Filters
Unix - Processes
Unix - Communication
Unix - The vi Editor
Unix - What is Shell?
Unix - Using Variables
Unix - Special Variables
Unix - Using Arrays
Unix - Basic Operators
Unix - Decision Making
Unix - Shell Loops
Unix - Loop Control
Unix - Shell Substitutions
Unix - Quoting Mechanisms
Unix - IO Redirections
Unix - Shell Functions
Unix - Manpage Help
Unix - Regular Expressions
Unix - File System Basics
Unix - User Administration
Unix - System Performance
Unix - System Logging
Unix - Signals and Traps
Unix - Useful Commands
Unix - Quick Guide
Unix - Builtin Functions
Unix - System Calls
Unix - Commands List
Unix Useful Resources
Computer Glossary
Who is Who
Copyright © 2014 by tutorialspoint
#include <sched.h> 

int sched_setscheduler(pid_t pid, int policy, 

                       const struct sched_param *param); 

int sched_getscheduler(pid_t pid); 

struct sched_param {
    ...
    int sched_priority;
    ...
};


int sched_setscheduler(pid_t pid, int policy, 

                       const struct sched_param *param); 


int sched_getscheduler(pid_t pid); 


struct sched_param {
    ...
    int sched_priority;
    ...
};


sched_getscheduler() queries the scheduling policy currently applied to the process
identified by pid. If pid equals zero, the policy of the
calling process will be retrieved.


SCHED_OTHER is the default universal time-sharing scheduler
policy used by most processes.
SCHED_BATCH is intended for "batch" style execution of processes.
SCHED_FIFO and SCHED_RR are
intended for special time-critical applications that need precise
control over the way in which runnable processes are selected for
execution.


Processes scheduled with SCHED_OTHER or SCHED_BATCH
must be assigned the static priority 0.
Processes scheduled under SCHED_FIFO or
SCHED_RR can have a static priority in the range 1 to 99.
The system calls sched_get_priority_min() and
sched_get_priority_max() can be used to find out the valid
priority range for a scheduling policy in a portable way on all
POSIX.1-2001 conforming systems.


All scheduling is preemptive: If a process with a higher static
priority gets ready to run, the current process will be preempted and
returned into its wait list. The scheduling policy only determines the
ordering within the list of runnable processes with equal static
priority.


Since Linux 2.6.12, the
RLIMIT_RTPRIO resource limit defines a ceiling on an unprivileged process’s
priority for the
SCHED_RR and
SCHED_FIFO policies.
If an unprivileged process has a non-zero
RLIMIT_RTPRIO soft limit, then it can change its scheduling policy and priority,
subject to the restriction that the priority cannot be set to a
value higher than the
RLIMIT_RTPRIO soft limit.
If the
RLIMIT_RTPRIO soft limit is 0, then the only permitted change is to lower the priority.
Subject to the same rules,
another unprivileged process can also make these changes,
as long as the effective user ID of the process making the change
matches the real or effective user ID of the target process.
See
getrlimit(2)
for further information on
RLIMIT_RTPRIO. Privileged
(CAP_SYS_NICE) processes ignore this limit; as with older older kernels,
they can make arbitrary changes to scheduling policy and priority.


Memory locking is usually needed for real-time processes to avoid
paging delays, this can be done with
mlock() or
mlockall(). 

As a non-blocking end-less loop in a process scheduled under
SCHED_FIFO or SCHED_RR will block all processes with lower
priority forever, a software developer should always keep available on
the console a shell scheduled under a higher static priority than the
tested application. This will allow an emergency kill of tested
real-time applications that do not block or terminate as expected.


POSIX systems on which
sched_setscheduler() and
sched_getscheduler() are available define
_POSIX_PRIORITY_SCHEDULING in <unistd.h>.


Standard Linux is
not designed to support
hard real-time applications, that is, applications in which deadlines
(often much shorter than a second) must be guaranteed or the system
will fail catastrophically.
Like all general-purpose operating systems, Linux
is designed to maximize average case performance
instead of worst case performance.
Linux’s worst case performance for
interrupt handling is much poorer than its average case, its various
kernel locks (such as for SMP) produce long maximum wait times, and
many of its performance improvement techniques decrease average time by
increasing worst-case time.
For most situations, that’s what you want, but
if you truly are developing a hard real-time application,
consider using hard real-time extensions to Linux such as
RTLinux (http://www.rtlinux.org) or RTAI (http://www.rtai.org)
or use a different operating system
designed specifically for hard real-time applications.

getpriority (2)
getpriority (2)
mlock (2)
mlock (2)
mlockall (2)
mlockall (2)
munlock (2)
munlock (2)
munlockall (2)
munlockall (2)
nice (2)
nice (2)
sched_get_priority_max (2)
sched_get_priority_max (2)
sched_get_priority_min (2)
sched_get_priority_min (2)
sched_getaffinity (2)
sched_getaffinity (2)
sched_getparam (2)
sched_getparam (2)
sched_rr_get_interval (2)
sched_rr_get_interval (2)
sched_setaffinity (2)
sched_setaffinity (2)
sched_setparam (2)
sched_setparam (2)
sched_yield (2)
sched_yield (2)
setpriority (2)
setpriority (2)

Advertisements


    129 Lectures 
     23 hours 

 Eduonix Learning Solutions

    5 Lectures 
     4.5 hours 

 Frahaan Hussain

    35 Lectures 
     2 hours 

 Pradeep D

    41 Lectures 
     2.5 hours 

 Musab Zayadneh

    46 Lectures 
     4 hours 

 GUHARAJANM

    6 Lectures 
     4 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page