# Real time but not as root



## ProphetOfDoom (May 30, 2022)

Hi there,
I’m trying to run qtractor (a digital audio workstation) with real-time scheduling priority. The rtprio command won’t work without sudo, but that causes it to run qtractor as root also. This is the command I’m using:

`sudo rtprio 0 qtractor &`

If I try to set the rtprio after the fact, like this:
`qtractor &`
`sudo rtprio 0 -pid`

qtractor is already complaining of lacking rt functionality before the second command has a chance to grant it the permission.
I’ve always been led to believe that we shouldn’t run GUI programs as root (or anything really if avoidable). I just want to run qtractor as a normal user but with rt.
I think I recall on Linux there was a real-time group you could add your user to, but I couldn’t find the FreeBSD equivalent??
Thanks for any suggestions.


----------



## covacat (May 30, 2022)

```
$!      Expands to the process ID of the most recent background command
             executed from the current shell.  For a pipeline, the process ID
             is that of the last command in the pipeline.  If this parameter
             is referenced, the shell will remember the process ID and its
             exit status until the wait built-in command reports completion of
             the process.
```


----------



## ProphetOfDoom (May 30, 2022)

Hi covacat,
I’ve tried that also, in a script I wrote, but qtractor, as I said, launches too quickly and spits out an error long before it gets awarded the right priority.
I have no idea if it can later recover from that error?


----------



## Alain De Vos (May 30, 2022)

Can't you just give as root the pids of the processes to the rtprio commands.


----------



## covacat (May 30, 2022)

```
~# rtprio 1 -$$
~# exec sudo -u nobody sh -c 'id;rtprio'
uid=65534(nobody) gid=65534(nobody) groups=65534(nobody)
rtprio: realtime priority 1
```


----------



## Styrsven (May 30, 2022)

There is a port to make this easier
https://www.freshports.org/sysutils/mac_rtprio


----------



## bakul (May 30, 2022)

AlexanderProphet said:


> If I try to set the rtprio after the fact, like this:
> `qtractor &`
> `sudo rtprio 0 -pid`
> 
> qtractor is already complaining of lacking rt functionality before the second command has a chance to grant it the permission.


One option is to _exec_ qtractor from a shell script like so:

```
cat >qf <<'EOF'
#!/bin/sh
sleep 5 # this gives rtprio 5 seconds to do its thing.
exec qtractor # this runs qtractor under the same pid as the shell script
EOF
chmod +x qf
qf & 
sudo rtprio 0 -pid
```


----------



## ProphetOfDoom (Jun 10, 2022)

Hi there, thanks everyone for your help.
In the end I needed to use the port sysutils/mac_rtprio (thanks Styrsven!) to give my group the realtime priority.
bakul's script does work (raises the priority) but this alone isn't enough to satisfy qtractor.
Apologies for taking more than a week to reply, I've been ill and so didn't feel much like recording music.


----------

