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


Click here to return to the 'obligatory corrections & shortcuts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
obligatory corrections & shortcuts
Authored by: mervTormel on Jan 13, '02 03:48:20PM

remaining true to the lazy programmer ethic, here are some shortcuts, and the obligatory correction for the above hint, lest you be confused:

first, to avoid the [ grep -v grep ] exclusion expression (running grep twice is a crime), use a bracketed character in the grep regexp; "[i]Tunes" -- the ps line for the grep command itself will not be selected since the string "iTunes" does not appear in it.

second, to avoid getting the iTuneshelper process, use the canonical form of the iTunes application, which should always look like this:

... /iTunes -psn_ ...

this will effectively give you the process you are looking for ...

% ps -axw | grep "[i]Tunes -p"
777 ?? RN 5:52.52 /Applications/iTunes.app/Contents/MacOS/iTunes /Applications/iTunes.app/Contents/MacOS/iTunes -psn_0_3407

the -w switch in the ps command is to wrap wide output to show you the full process context. it need not be in the final command.

then use awk to peel out the first column to get the process pid ...

% ps -axw | grep "[i]Tunes -p" | awk '{print $1}'
777

now, feed that to your renice command, but using priority 20, instead of 0, which is a noop.

renice 20 -p `ps -ax | grep "[i]Tunes -p" | awk '{print $1}'`


cheers



[ Reply to This | # ]
RE: corrections
Authored by: skyko on Jan 14, '02 04:11:41AM
It's just amaziong how much effort can be spend to optimize something that
  1. works
  2. just takes a split seconds even when not (yet) optimized
  3. is only run once
Compare that to the very useful tip to make it available in the script menu which spares opening a Terminal ... ;-)

[ Reply to This | # ]
RE: corrections
Authored by: TvE on Mar 28, '10 08:49:03AM

Well - it has one good side effect:
You'll learn to make better shell scripts (I was just reminded about the "grep [part]OfMySearchWord trick - Something I recently read about it in my O'Reilly BASH book

PS.: You are not FORCED to use the suggestions - it's voluntary (keep 'em coming!) ;-)



[ Reply to This | # ]