Question

I have given highest priority to sshd process using following command:

nice -n -20 /sbin/sshd

But it will give highest priority to child process (/bin/sh) also by default. So, is it possible to give normal priority (0) to child process instead of highest priority?

Was it helpful?

Solution 2

Its not possible to give normal priority to child process of niced process but we can assign normal priority in parent process code after fork() and before exec() of the child, this way we can assign normal priority to child process.

Refer setpriority for setting priority for any process from code

OTHER TIPS

Assuming this sshd is OpenSSH v4.4 or newer, you can probably get the effect you are looking for by setting the ForceCommand option in /etc/ssh/sshd_config to something like:

ForceCommand nice -n 0 $SSH_ORIGINAL_COMMAND

The ForceCommand feature is documented here. You can also use a Match block (documented in the same place) to modify the behavior for certain ports, users, IP addresses, etc.

The main gotcha (not mentioned in the docs) is that ForceCommand runs on the user's shell AFTER the execution of initialization scripts (eg .bashrc, etc) so the lowered priority won't apply until those startup scripts complete (hopefully those aren't doing anything compute intensive...).

Try using a niced shell command interpreter.

chsh -s "/usr/bin/nice -n 0 /bin/bash" username

Replace bash with your favorite shell.

You might get unexpected results by doing so, so please keep an extra session open as recovery option.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top