0

I have a process that does a small amount of work, then goes to sleep for 1-5ms. When that sleep time is up, I want that process to get the CPU IMMEDIATELY! Whatever process is already on the CPU needs to be ejected instantly to make way for the new process.

Is there a way to configure the process, w/ chrt or similar tools, to accomplish this?

2
  • 3
    If you need such strict deadlines for processing commands, you may need a Real Time Operating System. Otherwise you want to send an interrupt, but that doesn't work if you're not a hardware device driver, AFAIK.
    – zymhan
    Oct 8, 2018 at 21:36
  • @user37244 may I ask you to elaborate what you are trying to achieve? Aka what is the goal of all this? Because this doesn't seem like anything Linux was designed for, zymhan is right.
    – Broco
    Oct 9, 2018 at 1:20

1 Answer 1

0

I think you want to take a look at nice:

NICE(1)                    User Commands                    NICE(1)

NAME
       nice - run a program with modified scheduling priority

SYNOPSIS
       nice [OPTION] [COMMAND [ARG]...]

DESCRIPTION
       Run COMMAND with an adjusted niceness, which affects process
       scheduling.  With no COMMAND, print  the  current  niceness.
       Niceness  values  range  from  -20  (most  favorable  to the
       process) to 19 (least favorable to the process).

Note that if you want to increase the scheduling priority (by providing a negative nice value) you will need to have root (sudo) access. Normal users cannot increase priority, but only decrease.

To get highest priority scheduling, you would nee to run something like:

$ sudo nice --adjustment=-20 /your/application

Or, if your process is already running, you can change the priority like so:

$ sudo renice -n -20 [PID]
2
  • AFAIK, setting the nice level changes the decision-making process that gets a process onto the CPU, but doesn't allow a "mean" process to force the immediate pre-emption of another task. Processes with a real-time priority (0-99) have a default time slice of 200ms and "nice" processes (100-140) have a default TS of 10ms. In any case, it's possible for a process to be occupying all processors when my task's sleep completes. It'll go to the front of the scheduler's "queue", but still won't run until one of the running processes relinquishes - which could be as much as 199ms too late.
    – user37244
    Oct 8, 2018 at 20:11
  • Perhaps the info here would be useful as well: unix.stackexchange.com/questions/154867/…
    – guzzijason
    Oct 8, 2018 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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