This is a follow-up to an earlier hint regarding fast user switching and scheduling priority/cpu usage. One commenter suggested renicing user processes as part of login or logout script, but I prefer to run the following script as a cron job, for a couple of reasons. First, I can run the cron job as root (which renice requires to increase priority) without having SetUID programs lying around. Second, a periodic cron job catches at & batch jobs, periodic jobs, processes started via ssh, and other processes that are started by other users after logout or login.
B
The downside to this approach, of course, is that there is a certain variable lag time between login/user switching and a user's processes being reniced. The truly harried or impatient may want to run the script via sudo on login.

Save the following script someplace logical; I use /usr/sbin/ or /var/root/bin/.

#!/bin/sh
#
# switch_nice
#
# renice processes so that the user at the main login window gets priority
#
# Determine who is logged in at the main terminal
#
# The user currently logged on at the main main termainal will be returned
# as the final argument to the only instance of login running on std
TOPUSER=`ps -auxww | grep login | grep std | grep -v grep | awk '{print $13}'`
# Determine what other processes have been given priority by admins
# and ought to be exempt -- THE FOLLOWING SHOULD BE ONE LONG LINE WITH A
# SINGLE SPACE REPLACING THE LINE BREAK!
EXEMPTIONS=(`ps -auxo nice | awk '{print $1, $2, $11}' | grep -v root |
grep -v nobody | grep -e - | awk '{print $2}'`)
# Get names of users to be reniced -- THE FOLLOWING SHOULD BE ONE LONG
# LINE WITH A SINGLE SPACE REPLACING THE LINE BREAK!
SWITCHEDUSER=(`ps -auxww | grep -v $TOPUSER | grep -v root | grep -v nobody |
awk '{print $1, $2}' | grep -v USER | awk '{print $1}' | sort -u`)
# Renice: others to 15, main terminal to 0, priority processes to -15
echo ${SWITCHEDUSER[*]} | xargs renice 15 -u
renice 0 -u $TOPUSER
echo ${EXEMPTIONS[*]} | xargs renice -15 -p
# Add additional rules...I renice my seti@home instances to 20

Then chmod u+x and add the following to your /etc/crontab:

*/5 * * * * root </path/to/switch_nice>

Now every five minutes the system will check for processes run by other users and renice them.

The previous commenter's caveat is a good one. While I do not pretend to know enough Unix to pull this off, it seems that in principle one could use ps to identify a list of users with UID > 500 -- which I believe should only include "real live" users -- then exclude the current user from that list and renicing all processes with UIDs on that list down to 15.

It would be nice to be able to execute scripts upon "account activation" -- whether that be a login or an account switch via FUS. Ideas anyone?

Unix people will doubtless have worked this out already, but I post this here for "part-time fiddlers" such as myself who may need a pointer.

As the comment below notes, the SWITCHEDUSER variable can contain the names of system accounts such as www. This is undesirable. It's easy enough to modify the script to exclude these usernames, however:

in 10.4, when I run the printed TOPUSER line (as me or root), I get no results. As root,TOPUSER=`id -p | grep login | awk '{print $2}'`
does return me. (when running that line as me, I'd have to change the login to uid:TOPUSER=`id -p | grep uid | awk '{print $2}'`

I rewrote this a bit so that it works in 10.4 (well, at least the posted one didn't work for me)

#!/bin/sh
#
# switch_nice
#
# renice processes so that the user at the main login window gets priority
#optimization, only do the renice if the user has changed. Store that in /tmp
olduser=`cat /tmp/user`;
# Determine who is logged in at the main terminal
#
# The user currently logged on at the main main terminal will be returned
# as the final argument to the only instance of login running on std
x=`last -1| awk '{print $1}'`
TOPUSER=`ls -1 /Users/ | grep $x`
if (test $olduser != $TOPUSER); then
# the user has changed, so proceed
#change the user file so that olduser will get updated next time
echo "$TOPUSER" > /tmp/user;
# I like a bit of logging -- uncomment these if in the crontab you do
#<path/to/switchnice >> /var/log
#date
#echo "new user, now $TOPUSER"
# Determine what other processes have been given priority by admins
# and ought to be exempt [the next should be 1 line]
EXEMPTIONS=(`ps -auxo nice | awk '{print $1, $2, $11}' | grep -v root | grep -v nobody | grep -e - | awk '{print $2}'`)
# using /Users for real users instead of trying to get it from a tool, since
#there is less worry about system users and no truncation
# Get names of users to be reniced
SWITCHEDUSER=(`ls -1 /Users/ | grep -Ev '(.DS|.local|Shared)'`)
#rest as in original
# Renice: others to 15, main terminal to 0, priority processes to -15
#echo ${SWITCHEDUSER[*]}
echo ${SWITCHEDUSER[*]} | xargs renice 15 -u
renice 0 -u $TOPUSER
echo ${EXEMPTIONS[*]} | xargs renice -15 -p
# Add additional rules...I renice my seti@home instances to 20
fi