Seth Woolley's Man Viewer

sched_setaffinity(2) - sched_getaffinity, sched_setaffinity, sched_getaffinity, sched_setaffinity - set and get a process's CPU affinity mask - man 2 sched_setaffinity

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

SCHED_SETAFFINITY(2)       Linux Programmer's Manual      SCHED_SETAFFINITY(2)



NAME
       sched_setaffinity,  sched_getaffinity  -  set(7,n,1 builtins)  and  get a process's CPU
       affinity mask

SYNOPSIS
       #include <sched.h>

       int  sched_setaffinity(pid_t  pid,  unsigned  int  len,  unsigned  long
       *mask);

       int  sched_getaffinity(pid_t  pid,  unsigned  int  len,  unsigned  long
       *mask);

DESCRIPTION
       sched_setaffinity sets the CPU affinity mask of the process denoted  by
       pid.  If pid is zero, then the current process is used.

       The  affinity  mask  is represented by the bitmask stored in(1,8) mask.  The
       least significant bit corresponds to the first logical processor number
       on  the  system, while the most significant bit corresponds to the last
       logical processor number on the system.  A set(7,n,1 builtins)  bit  corresponds  to  a
       legally  schedulable CPU while an unset bit corresponds to an illegally
       schedulable CPU.  In other words, a process is bound to and  will  only
       run on processors whose corresponding bit is set.  Usually, all bits in(1,8)
       the mask are set.

       The argument len is the length (in(1,8) bytes) of the  data  pointed  to  by
       mask.  Normally this is the size of a word on the system.  For compati-
       bility with future versions of the Linux kernel, since  this  size  can
       change,  the bitmask supplied must be at least as large as the affinity
       mask stored in(1,8) the kernel.

       The function sched_getaffinity writes into the pointer supplied by mask
       that  has  size  len the affinity mask of process pid.  If pid is zero,
       then the mask of the current process is returned.


RETURN VALUE
       On success, sched_setaffinity returns 0.  On error(8,n), -1 is returned, and
       errno is set(7,n,1 builtins) appropriately.

       On success, sched_getaffinity always returns the size (in(1,8) bytes) of the
       affinity mask used by the kernel.  On error(8,n), -1 is returned, and  errno
       is set(7,n,1 builtins) appropriately.


ERRORS
       EFAULT A supplied memory address was invalid.

       EINVAL The affinity bitmask mask contains no processors that are physi-
              cally on the system, or the length len is smaller than the  size
              of the affinity mask used by the kernel.

       EPERM  The  calling  process does not have appropriate privileges.  The
              process calling sched_setaffinity needs  an  effective  user  ID
              equal to the user ID or effective user ID of the process identi-
              fied by pid, or it must possess the CAP_SYS_NICE capability.

       ESRCH  The process whose ID is pid could not be found.

HISTORY
       The affinity syscalls were  introduced  in(1,8)  Linux  kernel  2.5.8.   The
       library  calls  were  introduced  in(1,8)  glibc 2.3, and are still in(1,8) glibc
       2.3.2. Later glibc 2.3.2 development versions changed this interface to
       one without the len field, and still later versions reverted again. The
       glibc prototype is now

       /* Set the CPU affinity for a task */
       extern int sched_setaffinity (pid_t pid, size_t cpusetsize,
                                     const cpu_set_t *cpuset);

       /* Get the CPU affinity for a task */
       extern int sched_getaffinity (pid_t pid, size_t cpusetsize,
                                     cpu_set_t *cpuset);

SEE ALSO
       getpriority(2),  nice(1,2)(2),  sched_get_priority_max(2),  sched_get_prior-
       ity_min(2),   sched_getscheduler(2),  sched_setscheduler(2),  setprior-
       ity(2), capabilities(7)

       sched_setscheduler(2) has a description of the Linux scheduling scheme.



Linux                             2004-04-22              SCHED_SETAFFINITY(2)

References for this manual (incoming links)