How to use ioprio_set in linux c

Since there is no glibc wrapper for ioprio_set in linux c, we need to call this API with some definition.

Using syscall in linux as follows.

syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, pid, IOPRIO_PRIO_CLASS(IOPRIO_CLASS_IDLE));

Some other definitions to declare above macros.

  69 enum {                                                                                                     
  70     IOPRIO_CLASS_NONE,                                                                                     
  71     IOPRIO_CLASS_RT,                                                                                       
  72     IOPRIO_CLASS_BE,                                                                                       
  73     IOPRIO_CLASS_IDLE,                                                                                     
  74 };                                                                                                         
  75                                                                                                            
  76 enum {                                                                                                     
  77     IOPRIO_WHO_PROCESS = 1,                                                                                
  78     IOPRIO_WHO_PGRP,                                                                                       
  79     IOPRIO_WHO_USER,                                                                                       
  80 };     

  65 #define IOPRIO_CLASS_SHIFT  (13)                                                                           
  66                                                                                                            
  67 #define IOPRIO_PRIO_CLASS(mask) ((mask) >> IOPRIO_CLASS_SHIFT)

References:
ioprio.h source
ioprint_set manual

One comment:

Leave a Reply

Your email address will not be published. Required fields are marked *