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


Click here to return to the 'Better way to do the crucial line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Better way to do the crucial line
Authored by: Anonymous on Jan 18, '02 08:14:32PM

Here's a better way to do the key line of the shell script:

sudo renice -19 -p `ps -ax | grep Quake3 | awk '{print $1}'

Using grep twice is a crime. Using cut to display only one field of a line is a minor offense.

BTW, I have a command (pid) which is basically ps -auxc | grep $1 | awk as above - great for backquoting into kills and such.

In fact I just realized I should just do sudo renice -19 `pid Quake3`.

Oh, and setting a process to -20 is a REALLY bad idea - it means the entire system is locked up while the front app runs. Yes, you say, but that's what we want, just like on OS 9. Wrong - this is Unix. Background stuff happens that NEEDS to happen by itself. Interfering with that is asking for trouble. Just go with -19.



[ Reply to This | # ]
done and done
Authored by: brett_ on Jan 19, '02 01:57:59AM

thanks alot for the grep tip. i incorporated it. also, i used "property" lines so people can insert their own preferences easily -- path, mod, pwd, cfg & renice value. again, the script is on my homepage:

http://homepage.mac.com/bhduxbury/.cv/bhduxbury/Public/q3ut2-binhex.hqx

brett.



[ Reply to This | # ]
Better way to do the crucial line
Authored by: iv on Jan 19, '02 02:59:48AM

Yes, and remember that AWK is just a glorified version of grep, so we can save a process by using pattern matching in AWK:

sudo renice -19 -p `ps -ax | awk '/Quake3/ {print $1}' `

These unix-oneliners give Applescript just the power it used to lack in Mac OS 9; thanks for brett_ et al. for showing me the way to go!

BTW, for more on 'using grep twice is a crime' see, e.g., http://www.ling.helsinki.fi/~reriksso/unix/award.html

iv



[ Reply to This | # ]
Better then Better way to do the crucial line
Authored by: sing on Aug 27, '04 10:15:15AM
Why you use grep?

sudo renice -19 -p `ps -ax | grep Quake3 | awk '{print $1}'

Why not use command like this:
sudo renice -19 -p `ps -axw | awk 'match($5,"Quake3") {print $1}'



sumimasen. anatano Lisa... japanese is not supported :-(

[ Reply to This | # ]