4

I want to have a real-time process take over my computer. :)

I've been playing a bit with this. I created a process which is essentially a while (1) (never blocks nor yields the processor) and used schedtool to run it with SCHED_FIFO policy (also tried chrt). However, the process was letting other processes run as well.

Then someone told me about sched_rt_runtime_us and sched_rt_period_us. So I set the runtime to -1 in order to make the real-time process take over the processor (and also tried making both values the same), but it didn't work either.

I'm on Linux 2.6.27-16-server, in a virtual machine with just one CPU. What am I doing wrong?

Thanks,

EDIT: I don't want a fork bomb. I just want one process to run forever, without letting other processes run.

4
  • 1
    If you mean 'hang' as in 'slow down and crash', try a fork bomb. If I understand you correctly (and you're not tied to a kernel implementation), a fork bomb will do exactly what you need.
    – new123456
    Aug 28, 2010 at 0:45
  • I agree with ^ a fork bomb will do this much more effectively. Aug 28, 2010 at 0:49
  • No, I don't want that. I just want one process to run forever, without letting other processes run. Aug 28, 2010 at 1:01
  • This is actually a useful technique under some circumstances (particularly if you only do it with one task and have >1 core)
    – MarkR
    Aug 29, 2010 at 12:38

3 Answers 3

5

There's another protection I didn't know about.

If you have just one processor and want a SCHED_FIFO process like this (one that never blocks nor yields the processor voluntarily) to monopolize it, besides giving it a high priority (not really necessary in most cases, but doesn't hurt) you have to:

  1. Set sched_rt_runtime_us to -1 or to the value in sched_rt_period_us
  2. If you have group scheduling configured, set /cgroup/cpu.rt_runtime_us to -1 (in case you mount the cgroup filesystem on /cgroup)

Apparently, I had group scheduling configured and wasn't bypassing that last protection.

If you have N processors, and want your N processes to monopolize the processor, you just do the same but launch all of them from your shell (the shell shouldn't get stuck until you launch the last one, since it will have processors to run on). If you want to be really sure each process will go to a different processor, set its CPU affinity accordingly.

Thanks to everyone for the replies.

3

I'm not sure about schedtool, but if you successfully change the scheduler using sched_setscheduler to SCHED_FIFO, then run a task which does not block, then one core will be entirely allocated to the task. If this is the only core, no SCHED_OTHER tasks will run at all (i.e. anything except a few kernel threads).

I've tried it myself.

So I speculate that either your "non blocking" task was blocking, or your schedtool program failed to change the scheduler (or changed it for the wrong task).

2
  • In particular, were you running chrt as root?
    – caf
    Aug 30, 2010 at 1:53
  • 1
    @caf: Yes, I was. As I just stated in my answer, the problem wasn't the process itself nor schedtool or chrt. There was some other protection I wasn't aware of. Thanks. Aug 30, 2010 at 6:28
1

Also You can make you process a SCHED_FIFO with highest priority of 1. So the process would run forever and it wont be pre-empted.

1
  • Also you need to have some really busy wait loop in the same so that no one else get chance to even run
    – chandank
    Aug 9, 2013 at 4:18

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.