Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-17-2017, 06:07 AM   #1
Registered: Apr 2017
Posts: 31

Rep: Reputation: Disabled
Real time application programming - sched_setattr() fails if I set CPU affinity using sched_setaffinity().


Working on a real time application, Getting runtime error at sched_setattr as "Operation Not permitted".Running on Ubuntu 16.04 LTS (4.4.0-97-generic kernel, x86_64 platform)
C program code excerpt as below:

unsigned int flags = 0;
sched_getattr(0, &attr, sizeof (struct sched_attr), 0);
if (ret != 0)
perror("getattr failed:");
attr.sched_policy = SCHED_DEADLINE;
attr.sched_runtime = 5 * 100 * 1000;
attr.sched_deadline = 8 * 100 * 1000;
attr.sched_period = 10 * 100 * 1000;
attr.size = sizeof (attr);
attr.sched_flags = 0;
attr.sched_nice = 0;
attr.sched_priority = 0;

if(sched_setaffinity(0,sizeof(set), &set) < 0)
perror("sched_setaffinity :");
return 0;
ret = sched_setattr(0, &attr, flags);
perror("sched_setattr failed: ");

But, If I comment the sched_setaffinity() call, it runs without error. Also, using SCHED_FIFO by calling sched_setscheduler() doesn't give me any error after setting CPU affinity. Only the combination of sched_setaffinity with sched_setattr() generates error. I am running in sudo mode.

Thanks in advance,
Old 11-20-2017, 08:23 AM   #2
LQ Guru
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,604

Rep: Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604Reputation: 5604
would be nice to see what kind of error was generated....
Old 11-20-2017, 10:11 AM   #3
Registered: Apr 2017
Posts: 31

Original Poster
Rep: Reputation: Disabled
The error is:
sched_setattr failed : Operation not permitted

This corresponds to return error code of sched_setattr() : EPERM

Thank you


attribute, cpuaffinity, realtime, scheduler

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to set cpu affinity to all the tasks maheshajja Linux - Kernel 2 02-11-2015 09:19 AM
LXer: How to Change CPU Affinity of CPU Intensive Multithreaded Applications (Ubuntu) LXer Syndicated Linux News 0 12-10-2012 12:10 PM
real time application khodeir Programming 10 12-02-2009 09:38 AM
How do I manage CPU affinity FBO multiple instances of an application in RHEL v5.x? Kevin McLeod Linux - Newbie 2 02-05-2009 05:40 PM
CPU binding - How to modify the CPU affinity mask? Thaidog Linux - General 1 03-15-2008 05:54 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:23 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration