---
name: "pthread_attr_getcpu_np"
section: "3"
platform: "linux"
package: "rtlinux"
version: "2.0rel-1"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/pthread_attr_setcpu_np"
---

# pthread\_attr\_getcpu\_np(3)

examine and change the CPU pthread attribute

Part of [pthread\_attr\_setcpu\_np(3)](/pthread_attr_setcpu_np/3.md).

## NAME

pthread\_attr\_setcpu\_np, pthread\_attr\_getcpu\_np - examine and change the CPU pthread attribute

## SYNOPSIS

**#include \<rtl\_sched.h\>**

**int pthread\_sttr\_setcpu\_np(pthread\_attr\_t \*attr, int cpu);** **int pthread\_sttr\_getcpu\_np(pthread\_attr\_t \*attr, int \*cpu);**

## DESCRIPTION

These functions are non-portable Real-Time Linux extensions. On SMP machines they allow a thread to be scheduled on a specific CPU.

**pthread\_attr\_setcpu\_np** modifies the thread attribute object *attribute* so that the created thread would be scheduled on the CPU with id *cpu* (as displayed in */proc/cpuinfo* ). The thread attribute object *attr* first has to be initialized with  **[pthread\_attr\_init(3)](/pthread_attr_init/3.md).**

**pthread\_attr\_getcpu\_np** fills the location pointed to by *cpu* with the CPU id from the attribute structure.

## RETURN VALUE

All functions return 0 on success and a non-zero error code on error.

## ERRORS

**pthread\_attr\_getcpu\_np** returns **EINVAL** if the specified CPU does not exist in the system.

## NOTES

If **pthread\_attr\_setcpu\_np** was not used on the attribute object passed to pthread\_create, the thread is scheduled on the current CPU.

## AUTHOR

Michael Barabanov \<baraban@fsmlabs.com\>

## SEE ALSO

[**pthread\_attr\_getstacksize**(3)](/pthread_attr_getstacksize/3.md) [**pthread\_attr\_setstacksize**(3)](/pthread_attr_setstacksize/3.md) [**pthread\_attr\_setschedparam**(3)](/pthread_attr_setschedparam/3.md) [**pthread\_attr\_init**(3)](/pthread_attr_init/3.md) [**pthread\_attr\_getschedparam**(3)](/pthread_attr_getschedparam/3.md) [**pthread\_create**(3)](/pthread_create/3.md)
