Alan Hargreaves's Weblog

Who is renicing these processes?

Alan Hargreaves
Senior Principal Technical Support Engineer

I was helping out a colleague on such a call this morning. While the DTrace script I produced was not helpful in this actual case, I think it bear sharing, anyway.

What we wanted was a way to find out why various processes were running with nice set to -20. There are two ways in which a process can have its nice changed.

  • nice(2) - where it changes itself

  • priocntl(2) - where something else changes it

I ended up with the following script after a bit of poking around.

# dtrace -n '
syscall::nice:entry {
printf("[%d] %s calling nice(%d)", pid, execname, arg0);}
syscall::priocntlsys:entry /arg2 == 6/ {
this->n = (pcnice_t *)copyin(arg3, sizeof(struct pnice));
this->id = (procset_t *)copyin(arg1, sizeof(struct procset));
printf("[%d] %s renicing %d by %d",
pid, execname, this->id->p_lid, this->n->pc_val); }'

There is an assumption in there about p_lid being the PID that I want, but in this particular case it turns out to be ok. Matching arg2 against 6 is so that we only get priocntl() calls with the command PC_DONICE. I could have also had it check the pcnice_t->pc_op but I can put up with the extra output.

So what happens when we have this running and then try something like

# renice -20 4147
dtrace: description 'syscall::nice:entry ' matched 2 probes
0 508 priocntlsys:entry [4179] renice renicing 4147 by 0
0 508 priocntlsys:entry [4179] renice renicing 4147 by -20

Which is exactly what we wanted. We see the renice command (pid 4179) modifying pid 4179.

Oh, why didn't this help I hear you ask?

Turns out that in this instance, the process in question was being started by init from /etc/inittab, as such starting with nice set to whatever init is running at. In this case it is -20.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.