11

I know if I nice a shell script (ie: before it runs) all processes that start from the shell script will also be niced.

What if I start a shell script and the renice it, do all the child processes become reniced as well?

Looked in the renice man pages and there are no mention of child processes.

hhafez
  • 38,949
  • 39
  • 113
  • 143

1 Answers1

11

Children inherit the current priority of a process when they're created. That means, if you renice the parent and start a child, it will have the modified priority.

Children that are already running when you renice are not affected.

The clue is in the fork() man pages (starting a child is a fork/exec operation):

fork() creates a child process that differs from the parent process only in its PID and PPID, and in the fact that resource utilizations are set to 0.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • In the case of a shell using the process group (-g) option of renice also won't change currently running children as each command they execute goes into a different process group. But most programs will not change the process group of their children so it's a way to alter related processes. – George Phillips Jun 30 '09 at 06:51
  • Yeah, I figured by "renice on a parent", the questioner meant that specific PID. Obviously if you renice a process group or user, other processes may be affected. – paxdiablo Jun 30 '09 at 07:08
  • @paxdiablo:I want child process to start with its default priority 0 not on priority of parent process then? – Rahul R Dhobi Apr 07 '14 at 06:09
  • @Rahul, the correct way to ask a question is _ask a question,_ not make a comment to a question that almost no-one bar the author will see. – paxdiablo Apr 07 '14 at 06:10
  • @paxdiablo: Already asked question http://stackoverflow.com/questions/22904588/niced-process-gives-their-priority-to-child-process? – Rahul R Dhobi Apr 07 '14 at 06:15