Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.3: Control CPU usage while using fast user switching' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: Control CPU usage while using fast user switching
Authored by: jen729w on Mar 12, '05 12:20:13AM
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:

  1. Copy the TOPUSER=`ps -auxww | grep login | grep std | grep -v grep | awk '{print $13}'` line from the script into a Terminal window and hit return. Nothing much will happen.
  2. Copy the SWITCHEDUSER=(`ps -auxww | grep -v $TOPUSER | grep -v root | grep -v nobody | awk '{print $1, $2}' | grep -v USER | awk '{print $1}' | sort -u`) line into a Terminal window and hit return. (Make sure it's all on one line - you may have to copy 'n paste twice without hitting return in the middle.) Again, nothing much happens.
  3. Type set in Terminal. You'll be shown a list of variables - look for the SWITCHEDUSER line. Mine looks like this:
    SWITCHEDUSER=([0]="will" [1]="www").
  4. In this case, will is my flatmate, whose processes I want to renice. www is the system service, which I want to leave alone.
  5. In the script, edit the SWITCHEDUSER line, adding a grep -v [system-account-name] | statement for each system account. Add the statement immediately after the grep -v nobody | statement. My script therefore now contains the following line:
    SWITCHEDUSER=(`ps -auxww | grep -v $TOPUSER | grep -v root | grep -v nobody | grep -v www | awk '{print $1, $2}' | grep -v USER | awk '{print $1}' | sort -u`)
    ...but yours may contain more entries depending on what was contained in SWITCHEDUSER.
  6. All done. Go and put the kettle on.

This still isn't perfect - any new services which are installed in the future won't be reniced. It's up to you to remember and add their account names to the script.

I hope that all makes sense (and that it helps someone, somewhere). :-)

j.

[ Reply to This | # ]