changing priorities

MasonMcD

Registered
Is there any way to say, give an MP3 player or some other real-time app greater access to the processor or memory or disk? I'm tired of the player skipping everytime the mail app indexes or I switch apps.
 
There is a way to do this with the command line tools, I think. I'm looking into it and if I find anything I'll probably end up making a UI for this.
 
The UI is basially done and I can call the commands(tested with cd, ls, and others) but I'm still trying to learn just how nice and renice work. If someone wants to help out that would be great. Anything on priority control would help.

thanks in advance!

[Edited by IamBob on 11-02-2000 at 12:39 AM]
 
Can't help further, Bob, but this will be a flourishing area, methinks.

Services and the new RealBasic should make it incredily easy to whip up front-ends to the GUI.

A fine example of what can be done is Brickhouse.
 
Okay, I'm done....for the most part.

The only thing left, I guess, is to add a way to su from the GUI.

I'm waiting for the developer tools to land on my porch(due tuesdayish) so for now it's only runnable from the command line with the following(assuming it's in your home directory);
java -cp DoRenice.jar DoRenice

if you really want to tweak things you can type su and enter the root password before typing the above command.

I couldn't think of a better name and DoRenice seemed to work...any ideas? I'm also looking for a place to put up the binary. I can't seem to find a decent place to put up a simple site(my computer isn't an option :-().

Well, post if you're interested, I guess.

l8r
 
Originally posted by IamBob
I'm also looking for a place to put up the binary. I can't seem to find a decent place to put up a simple site(my computer isn't an option

Good work.
You can put the binary on our university's FTP server if you want. I cannot provide room for a site though.

I am very interested in your source. I tried to make a GUI for Samba, but i got stuck on the prompt Samba returned. Since you can su and type the password it seems you have a solution for that. Can you mail me a copy (or part of it) to me? I would be very gratefull.

DJ
hartman@mac.com
 
Why not just sign up for an idisk account and put it up there? You get plenty of space for small transfers and just put it in your public folder. If you really need someplace to put it up, email it to me at fahrenba@uiuc.edu and I'll put it up on my site.

To get a command line program executable from the GUI:
change the extension to .command from whatever it was before.

HTH,
F-bacher
 
http://www.1avenue.com/thenamethief/ ..I hope.

I guess I'm too lazy to get an idisk account.

Is that .command thing foreal? I had to bounce into OS9 so I can't try it right now but for some reason I don't think it'll work in this case. I s'pose it can't hurt to try though. I am getting the developer tools shortly so I should be able to get it to run without the Terminal at that point.

feel free to suggest a new name for it...DoRenice kinda sucks.
 
Okay, basically every process has a priority attached to it.. the default is 0. -20 is the most aggressive, (given the most CPU time) with 20 being the least (given the least CPU time). If all your processes are prioritized at 0 however (which they most likely will be unless you specify otherwise) and you want to reprioritize your MP3 player for example.. It will make NO difference whether you set it to -1 or -20.. Basically -1 is still lower than 0 so it will get priority, period. the 20 levels below and above 0 are just for flexibility if you want to set multiple levels of priority. Annnnyway.. only root (super-user) can renice a process for below 0. Any user can do it above 0.. So only root can give a process more CPU time via renice. The difference in commands between renice and nice is the following.. nice is a runtime command.. meaning that if you do 'nice -1 top' top will run at priority -1. This is specified right on the command line or in the script or whatever, and this is not used to reprioritize an existing process (hence renice). renice is used to change the priority on an already running process. for instance if netscape is hogging up all your CPU for some reason (what a surprise!) But you dont give a sh*t about netscape, you want taht CPU time for your MP3 Player! You would do (is their a GUI for this? I haven't used OS X that much) renice -1 PID (PID can be found in the top display or by using ps and its various arguments.. ps auxw will display all running processes on the system. All of these commands should also have manpages, so if you have further questions on nice/renice/ps, please do a man nice, man renice, or man ps respectively. Or if you're still stuck you can email me if you like..

Anyway, hope this helps!

-JD- (geniusj@ods.org)
 
geniusj, that is exactly what my program does. It is a GUI program that calls on ps to get PID, PPID, nice value, user and process name. It displays this in a table. There's a simple slider with labels(high, normal, low) and a button(set).

you select the process you want to change the priority on in the table, adjust the value in the slider and hit the set button(this calls renice with the proper info). It will either change the nice value or report back that you have to be root to execute the command. If the process was reniced it will update the table to reflect that.

This way, I(and others) don't have to do all this manually and everything is at hand to fully manage priorities. A few simple features are missing but this will get fixed.

My developer tools cd arrived yesterday but I wasn't at my mailbox so they are now waiting for me at the post office. As soon as I get them I'll be working on this. As soon as I'm satisfied with how it looks/works I'll probably post it on versiontracker or the like as freeware.

l8r.
 
I had considered BeNice but that sounds like it would be a BeOS app. I'm going with Nicer, I think.

There should be an update sometime soon now that have I have the dev tools.

l8r.
 
IamBob-

I am very interested in learning how to access the command line utilities from a GUI. Is there a chance you would be so kind to release your source (Renice.jar) so I could see how to access command-line tools? (I am online developer and have the dev. tools, in case you have a PB Project by now) Or can you be so kind as to point me to a place to find out how to access command-line tools?

Thanks so much! :)

Email: G4RulezAll@hotmail.com

[Edited by G4Rules on 11-14-2000 at 04:38 PM]
 
Originally posted by G4Rules

I am very interested in learning how to access the command line utilities from a GUI. Is there a chance you would be so kind to release your source (Renice.jar) so I could see how to access command-line tools? (I am online developer and have the dev. tools, in case you have a PB Project by now) Or can you be so kind as to point me to a place to find out how to access command-line tools?

I asked that question earlier and it still stands.
Help us plz.

DJ
 
I guess it depends on the langauge you want to use.

Since I'm using Java I use a simple class to call the commands...

import java.io.*;

public class ShellAccess {
public static String doCommand(String command) {
try {
Runtime r = Runtime.getRuntime();
String msg = "", emsg = "", output="";
Process p = r.exec(command);
p.waitFor();


BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader in2 = new BufferedReader(new InputStreamReader (p.getErrorStream()));

while ((msg = in.readLine()) != null)
output += " "+msg;

while ((emsg = in2.readLine()) != null)
output += " "+msg;

p.destroy();

} catch(Exception e) { System.out.println(e.toString()); }
return output;
}

}

Then, in one of your classes you can call;

ShellAccess.doCommand("cd library/dekstop/");
System.out.print(ShellAccess.doCommand("ls"));

..or the like.

DJ, my mail was on the fritz when I tried sending it. I'm really sorry..I forgot.

Hope that helps! :)
 
Originally posted by IamBob

DJ, my mail was on the fritz when I tried sending it. I'm really sorry..I forgot.

Hope that helps! :)

I use Java too.
I had something similar, but the problem is that samba returns a prompt of it's own. So i have to create some sort of output stream towards the process. Still haven't figured out how to do that exactly. Well, i'll continue looking.

And no prob. ;-)
 
Thanks so much. You make it look so easy! (Well, I guess it is if you know the right class to use!)

I appreciate your help :)
 
for what you're doing...how 'bout:

import java.io.*;

public class ShellAccess {
Process p;

ShellAccess() {}

public IOClass startProcess(String command) { //for the initail call.
try {
Runtime r = Runtime.getRuntime();
p = r.exec(command);
p.waitFor();

BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader err = new BufferedReader(new InputStreamReader (p.getErrorStream()));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));

return new IOClass(in, err, out);

} catch(Exception e) { System.out.println(e.toString()); }

return null; //failed.
}

public void destroy() throws llegalThreadStateException { p.destroy(); }

}

//IOClass.java
import java.io.*;

class IOClass {
public BufferedReader in;
public BufferedReader err;
public BufferedWriter out;

public IOClass(BufferedReader in, BufferedReader err, BufferedWriter out) {
this.in = in;
this.err = err;
this.out = out;
}

public void doCommand(String command) throws IOException {
out.write(command, 0, command.length());
out.flush();
}

//add some way to 'listen' to the input streams...you can do that :)

public void destroy() throws IOException {
in.close();
err.close();
out.close();
}

}


to use:
ShellAccess sa = new ShellAccess();
IOClass io = sa.startProcess("foo bar");
if (io != null)
try {
io.doCommand("dance in circles!");
} catch (IOException e) {/*maybe the streams are 'broken' or something*/}

//done with it..
try {
io.destroy();
sa.destroy();
} catch (Exception e) {/*not much you can do here*/}
sa = null; io = null;

maybe? I'm sure you'll figure it out eventually.

[fixed code...3 times!]

[Edited by IamBob on 11-17-2000 at 12:43 AM]
 
Should have tried compilin ur code first :p Looks like output goes out of scope because u created it inside try... but then u call it outside of try. Bad java code, Bad.

F-bacher
 
Back
Top