# Re: PTB linux privileges \[realtime scheduling\]

**URL:** https://psychtoolbox.discourse.group/t/re-ptb-linux-privileges-realtime-scheduling/549
**Category:** Uncategorized
**Created:** [September 22, 2010, 11:27pm UTC](https://psychtoolbox.discourse.group/t/re-ptb-linux-privileges-realtime-scheduling/549 "2010-09-22T23:27:41Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)
#### Post date: [September 22, 2010, 11:27pm UTC](https://psychtoolbox.discourse.group/t/re-ptb-linux-privileges-realtime-scheduling/549/1 "2010-09-22T23:27:41Z")

</div>

On Sep 22, 2010, at 11:07 AM, Jiri Lukavsky wrote:  
  

> \> Hi Mario,  
> \>  
> \> my name is Jiri and we met at ECVP. By the way, thanks first for the  
> \> hint about linux real-time kernel. It was really easy to install  
> \> (Ubuntu 10.04).  
> \> In our talk you mentioned it is possible to set the privileges under  
> \> linux so matlab can be run in real-time mode even under non-root user.  
> \> Can you tell me any details/links how to set this up, please? I  
> \> guessed it has something to do with sudoers file (?), but even after  
> \> reading the man page and few experiments, I am not sure hot to do  
> \> this.  
> \> I decided to write to you first, before asking in PTB mailing list,  
> \> since we partly discussed this at ECVP.  
> \>

Hi Jiri,  
  
forwarding this to the ptb forum.  
  
You have to edit the file /etc/security/limits.conf with a text   
editor, e.g.,  
  
sudo pico /etc/security/limits.conf  
  
I think you have to log out and log in again for it to have an effect.  
  
In that file you can set various resouce limits for users or groups.   
E.g., my username is kleinerm and my file has the following lines at   
its end:  
  
@kleinerm - rtprio 10  
@kleinerm - memlock 4300000  
  
# End of file  
  
This allows user kleinerm to use realtime scheduling up to priority   
level 10 (aka Priority(10)). The maximum would be 99, but usually   
Priority(1) does everything you need. Certain internal ptb threads   
will try to go a few levels beyond of what you set with the Priority   
() command, so it is good to leave some headroom. A process/thread   
with a certain level can only get preempted/delayed by processes with   
a higher priority level, but on typical system configurations, there   
aren't any other hard realtime applications, so the actual level   
doesn't matter as long as it is \> 0.  
  
The memlock parameter allows Matlab/Octave to lock up to 4300000 kb   
or 4300 MB aka \> 4 GB of the available memory. As Matlab/Octave can   
use at most 4 GB of memory this means effectively "unlimited". Locked   
memory is exclusively reserved for Matlab/Octave, never given away to   
other running applications or paged out to disk, so timing should be   
unaffected even if other applications decide to user large amounts of   
memory while your script is running. This is one of many features   
that OS/X or Windows don't have to offer at all. PTB uses memory   
locking as soon as Priority() is called with a non-zero value.  
  
It's of course better to not run as root, but i still wonder why the   
license manager would make trouble. I can run my Matlab as root/sudo   
on Linux with a network license manager without any trouble.  
  
best,  
-mario  
  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Mario Kleiner  
Max Planck Institute for Biological Cybernetics  
Spemannstr. 38  
72076 Tuebingen  
Germany  
  
e-mail: [mario.kleiner@...](mailto:mario.kleiner@...)  
office: +49 (0)7071/601-1623  
fax: +49 (0)7071/601-616  
www: [http://www.kyb.tuebingen.mpg.de/~kleinerm](http://www.kyb.tuebingen.mpg.de/~kleinerm)  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
"For a successful technology, reality must take precedence  
over public relations, for Nature cannot be fooled."  
(Richard Feynman)

---

<div class="post-metadata">

### Author: ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)
#### Post date: [September 23, 2010, 7:36am UTC](https://psychtoolbox.discourse.group/t/re-ptb-linux-privileges-realtime-scheduling/549/2 "2010-09-23T07:36:58Z")

</div>

Hi Mario,  
  
thanks! I can confirm this worked for me on Ubuntu 10.04 with Matlab 2009a.  
  
Licence manager - I think it depends on the licence program. I have  
"Standalone Named User" licence, which means I can run Matlab on few  
computers, but it can be used only by me (single user). Thus the  
licence is bound to a certain user account and licence manager  
complained when I did sudo on Linux (on Mac it worked). With your  
advice it is no longer a problem to run Matlab with normal user  
account.  
  
Best,  
  
Jiri  
  
  
On Thu, Sep 23, 2010 at 1:27 AM, Mario Kleiner  
\<[mario.kleiner@...](mailto:mario.kleiner@...)\> wrote:  

> \> On Sep 22, 2010, at 11:07 AM, Jiri Lukavsky wrote:  
> \>  
> \>\> Hi Mario,  
> \>\>  
> \>\> my name is Jiri and we met at ECVP. By the way, thanks first for the  
> \>\> hint about linux real-time kernel. It was really easy to install  
> \>\> (Ubuntu 10.04).  
> \>\> In our talk you mentioned it is possible to set the privileges under  
> \>\> linux so matlab can be run in real-time mode even under non-root user.  
> \>\> Can you tell me any details/links how to set this up, please? I  
> \>\> guessed it has something to do with sudoers file (?), but even after  
> \>\> reading the man page and few experiments, I am not sure hot to do  
> \>\> this.  
> \>\> I decided to write to you first, before asking in PTB mailing list,  
> \>\> since we partly discussed this at ECVP.  
> \>\>  
> \>  
> \> Hi Jiri,  
> \>  
> \> forwarding this to the ptb forum.  
> \>  
> \> You have to edit the file /etc/security/limits.conf with a text editor,  
> \> e.g.,  
> \>  
> \> sudo pico /etc/security/limits.conf  
> \>  
> \> I think you have to log out and log in again for it to have an effect.  
> \>  
> \> In that file you can set various resouce limits for users or groups. E.g.,  
> \> my username is kleinerm and my file has the following lines at its end:  
> \>  
> \> @kleinerm - rtprio 10  
> \> @kleinerm - memlock 4300000  
> \>  
> \> # End of file  
> \>  
> \> This allows user kleinerm to use realtime scheduling up to priority level 10  
> \> (aka Priority(10)). The maximum would be 99, but usually Priority(1) does  
> \> everything you need. Certain internal ptb threads will try to go a few  
> \> levels beyond of what you set with the Priority() command, so it is good to  
> \> leave some headroom. A process/thread with a certain level can only get  
> \> preempted/delayed by processes with a higher priority level, but on typical  
> \> system configurations, there aren't any other hard realtime applications, so  
> \> the actual level doesn't matter as long as it is \> 0.  
> \>  
> \> The memlock parameter allows Matlab/Octave to lock up to 4300000 kb or 4300  
> \> MB aka \> 4 GB of the available memory. As Matlab/Octave can use at most 4 GB  
> \> of memory this means effectively "unlimited". Locked memory is exclusively  
> \> reserved for Matlab/Octave, never given away to other running applications  
> \> or paged out to disk, so timing should be unaffected even if other  
> \> applications decide to user large amounts of memory while your script is  
> \> running. This is one of many features that OS/X or Windows don't have to  
> \> offer at all. PTB uses memory locking as soon as Priority() is called with a  
> \> non-zero value.  
> \>  
> \> It's of course better to not run as root, but i still wonder why the license  
> \> manager would make trouble. I can run my Matlab as root/sudo on Linux with a  
> \> network license manager without any trouble.  
> \>  
> \> best,  
> \> -mario  
> \>  
> \> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> \> Mario Kleiner  
> \> Max Planck Institute for Biological Cybernetics  
> \> Spemannstr. 38  
> \> 72076 Tuebingen  
> \> Germany  
> \>  
> \> e-mail: [mario.kleiner@...](mailto:mario.kleiner@...)  
> \> office: +49 (0)7071/601-1623  
> \> fax: +49 (0)7071/601-616  
> \> www: [http://www.kyb.tuebingen.mpg.de/~kleinerm](http://www.kyb.tuebingen.mpg.de/~kleinerm)  
> \> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> \> "For a successful technology, reality must take precedence  
> \> over public relations, for Nature cannot be fooled."  
> \> (Richard Feynman)  
> \>  
> \>
