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

10.3: Reclaim CPU cycles lost via fast user switching System
Recently, I discovered that my iBook had its CPU pegged even though I was only using Safari and a few other small apps. Turns out another user left Microsoft Word running in her account (via fast user switching), and that was eating some 70% of the CPU cycles. I didn't want to kill her process or forcefully log her out (as discussed in this hint), as I didn't know if she had any unsaved documents. But another recent hint gave me the idea of how to "pause" her processes and thereby reduce the CPU utilization. (Note: You will need to have administrative privileges in order to use this hint.)

First, you need to find the PID (process ID #) corresponding to the applications you want to "pause." This could be done by showing "Other User Processes" with Activity Monitor (in the Utilities folder), or in the Terminal with top or ps -U username. Then, launch Terminal.app and type:

sudo kill -STOP 1234
where 1234 is replaced with the process ID you found above. Another check with top or the Activity Monitor should confirm that 0.0% of the CPU is being used -- the application is "paused!"

To "resume" the application, type:

sudo kill -CONT 1234
It is really important to remember to "resume" the application before the other user switches back to their account: if you don't, they will see the spinning beach ball and the "Application Not Responding" message (when control-clicking on the "paused" application's dock icon). If they are not UNIX savvy (or have been locked out of the Terminal), they will have no recourse but to Force Quit their program and lose all their unsaved changes (which, of course, would defeat the purpose of this hint in the first place!).

I'm sure that someone more script-savvy could find a way to bundle this all up into a nice little app (giving credit, of course... ;) ). Or perhaps Apple will add a "Pause" option to the "Quit" and "Inspect" options under the "Process" menu of the Activity Monitor in a forth-coming 10.3.x.

    •    
  • Currently 1.71 / 5
  You rated: 2 / 5 (7 votes cast)
 
[12,132 views]  

10.3: Reclaim CPU cycles lost via fast user switching | 7 comments | Create New Account
Click here to return to the '10.3: Reclaim CPU cycles lost via fast user switching' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
better yet
Authored by: SOX on Jan 06, '04 10:32:19AM

instead of pausing the jobs instead renice them to 20 so they only run if you are not doing something more important. If you forget to unrenice them then its only a minor, probably unnoticed, inconvenience for the other user.



[ Reply to This | # ]
remind me about renice again?
Authored by: jiclark on Jan 06, '04 05:18:39PM

"renice 20" makes the app lower in priority then anything else, and "-20" ups the priority? And what do the numbers represent?

Thanks,
John-o



[ Reply to This | # ]
a possible script
Authored by: SOX on Jan 06, '04 10:42:54AM
Use the following script (or make a terminal icon out of it) to switch users by saving this as "fus", make it executable , and type: fus

#!/bin/sh
renice 20 -u $USER 
if [[ -z $1 ]]; then
  # robg note: Please enter the next two lines as one without
  # any spaces between "
  /System/Library/CoreServices/Menu\ Extras/user.menu/Contents/Resources/CGSessi
on -suspend
else
  userID=`id -u $1`;
  if [[ -z $userID ]]; then
    exit -1;
  fi;
  # robg note: Please enter the next two lines as one without
  # any spaces "
  /System/Library/CoreServices/Menu\ Extras/user.menu/Contents/Resources/CGSessi
on -switchTouserID $userID
fi;
I'm not quite sure where to put the hook to renice the new user back to 10. But the new user could type

renice 10 -u $USER
to restore his/her own priority

[ Reply to This | # ]
slight problem...
Authored by: MattHaffner on Jan 06, '04 11:36:47AM
The hitch with renice-ing is that the user can't restore their processes to the proper level without sudo privileges. You are only allowed to increase your own process nice level, not decrease it.

If you allow all your users to have sudo then it's not an issue, and you could hook a "renice 10 -u $userID" in before the -switchTouserID line. The script will always have to be run 'sudo', of course.

[ Reply to This | # ]

slight problem...
Authored by: SOX on Jan 06, '04 05:00:54PM

Maybe one could just make this a setUID executable with the owner as root and executable by all. If that were done then you could also use the root priviledge to set the nice level of the incoming user to 0 or 10 or something good in the same script.
that is add:

renice 10 -u $1
to the end.



[ Reply to This | # ]
FUS++
Authored by: jecwobble on Jan 06, '04 01:30:22PM
I haven't tried this software yet, but maybe some script could be executed by using this FUS replacement: FUS++

[ Reply to This | # ]
10.3: Reclaim CPU cycles lost via fast user switching
Authored by: Crest on Mar 29, '04 05:57:32AM

their is a great tool for pausing apps called "cunning fox" look at macupdate.com it's realy usefull if you're running more than 5 programms at one time.



[ Reply to This | # ]