2

Suppose I have a child process, whose scheduling policy I have set to be SCHED_BATCH, using the C library's function, sched_setscheduler, and now, this child process creates an external process using the execvp system call.

Will the Scheduler of the new process created be the same as that of the former child process, i.e., are the scheduling policies inherited through the execvp system-call ? I have read the man page, which states that FIFO and RR policies are inherited, but what about the normal policies, like SCHED_BATCH, SCHED_IDLE and SCHED_OTHER ?

Is there any execfamily's function which supports the inheritance of all the scheduling policies ?

Jarvis
  • 8,494
  • 3
  • 27
  • 58

1 Answers1

0

Firstly, exec family of system calls does not executes it's own image rather it executes the binary it loads. As per man exec:

The exec() family of functions replaces the current process image with a new process image.

So, it'll behave how that particular executable image was prepared to be scheduled.

When a process it marked to be scheduled as SCHED_BATCH, they will be scheduled based on their nice values just like SCHED_OTHER. Since, batch tasks doesn't require user interaction therefore scheduler treats the task as CPU-intensive. As per man sched_setschedparam quote from SCHED_BATCH: Scheduling batch process -

This policy is similar to SCHED_OTHER in that it schedules the process according to its dynamic priority (based on the nice value).The difference is that this policy will cause the scheduler to always assume that the process is CPU-intensive. Consequently, the scheduler will apply a small scheduling penalty with respect to wakeup behaviour, so that this process is mildly disfavored in scheduling decisions.

Therefore, if you change a process's scheduling policy to SCHED_BATCH, it'll be scheduled just like almost any other normal processes (SCHED_OTHER, the default scheduling policy). If you want to fallback to the fully default behavior then you have to utilize SCHED_RESET_ON_FORK flag ORed with the scheduling policy. If you specify that flag, any newly created process will fallback to default scheduling policy rather copying parent's behavior.

Hope this helps!

rakib_
  • 136,911
  • 4
  • 20
  • 26
  • Basically what I am asking is somewhat different, I am first setting the scheduler of a newly `forked` child process to be `SCHED_IDLE` using `sched_setscheduler`, now this forked child process creates a new process using `execvp` system-call, thus replacing the image of the child process, So, will this newly created process will also have the same scheduler, `SCHED_IDLE`, as that of the child process, which created it, or it may be different ? – Jarvis Sep 24 '16 at 09:29
  • Again, `execvp` does not create new process, it replaces calling process's image. There's a difference between fork() and exec(). `fork()` duplicates the calling process (which means creates new space in memory, execvp doesn't). – rakib_ Sep 24 '16 at 09:37
  • Yeah, so if it replaces its image, then the scheduler of the former process will be the same for the new process, right ? – Jarvis Sep 24 '16 at 10:04
  • No, it'll be as per new process's priority. – rakib_ Sep 24 '16 at 14:28
  • Your comments read inconsistent: "*does not create new process*" vs. "*as per new process's priority.*" – alk Sep 25 '16 at 08:56
  • @alk yeah it might sounds like that but what I meant there is "creating new process" (by fork) and "as per new process's priority" I meant newly loaded by execve. – rakib_ Sep 25 '16 at 10:31