sched_setaffinity() - 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_setaffinity(pid_t pid, unsigned int cpusetsize, 
                      cpu_set_t *mask); 

int sched_getaffinity(pid_t pid, unsigned int cpusetsize, 
                      cpu_set_t *mask); 

void CPU_CLR(int cpu, cpu_set_t *set); 

int CPU_ISSET(int cpu, cpu_set_t *set); 

void CPU_SET(int cpu, cpu_set_t *set); 

void CPU_ZERO(cpu_set_t *set); 


int sched_setaffinity(pid_t pid, unsigned int cpusetsize, 
                      cpu_set_t *mask); 


int sched_getaffinity(pid_t pid, unsigned int cpusetsize, 
                      cpu_set_t *mask); 


void CPU_CLR(int cpu, cpu_set_t *set); 

int CPU_ISSET(int cpu, cpu_set_t *set); 

void CPU_SET(int cpu, cpu_set_t *set); 

void CPU_ZERO(cpu_set_t *set); 


A CPU affinity mask is represented by the
cpu_set_t structure, a "CPU set", pointed to by
mask. Four macros are provided to manipulate CPU sets.
CPU_ZERO() clears a set.
CPU_SET() and
CPU_CLR() respectively add and remove a given CPU from a set.
CPU_ISSET() tests to see if a CPU is part of the set; this is useful after
sched_getaffinity() returns.
The first available CPU on the system corresponds to a
cpu value of 0, the next CPU corresponds to a
cpu value of 1, and so on.
The constant
CPU_SETSIZE (1024) specifies a value one greater than the maximum CPU
number that can be stored in a CPU set.


sched_setaffinity() sets the CPU affinity mask of the process whose ID is
pid to the value specified by
mask. If
pid is zero, then the calling process is used.
The argument
cpusetsize is the length (in bytes) of the data pointed to by
mask. Normally this argument would be specified as
sizeof(cpu_set_t). 

If the process specified by
pid is not currently running on one of the CPUs specified in
mask, then that process is migrated to one of the CPUs specified in
mask. 

sched_getaffinity() writes the affinity mask of the process whose ID is
pid into the
cpu_set_t structure pointed to by
mask. The
cpusetsize argument specifies the size (in bytes) of
mask. If
pid is zero, then the mask of the calling process is returned.


A child created via
fork(2)
inherits its parent’s CPU affinity mask.
The affinity mask is preserved across an
execve(2).


This manual page describes the glibc interface for the CPU affinity calls.
The actual system call interface is slightly different, with the
mask being typed as
unsigned long *, reflecting that the fact that the underlying implementation of CPU
sets is a simple bitmask.
On success, the raw
sched_getaffinity() system call returns the size (in bytes) of the
cpumask_t data type that is used internally by the kernel to
represent the CPU set bitmask.

clone (2)
clone (2)
getpriority (2)
getpriority (2)
gettid (2)
gettid (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_getscheduler (2)
sched_getscheduler (2)
sched_setscheduler (2)
sched_setscheduler (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