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


Click here to return to the 'Keep track of stopped processes via shell variables' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Keep track of stopped processes via shell variables
Authored by: colmc on Dec 15, '03 11:44:57AM
To make this more general you can use the following commands to find the process id of a program i.e. to find the Process Id of the Running Terminal.app you could use:

% ps -auxww | grep Terminal | grep -v grep | awk '{print $2}'
So to make your WORD variable up to date you could use, in csh:

% setenv WORD `ps -auxww | grep "Microsoft Word" | grep -v grep | awk '{print $2}'`
or in bash:

% export WORD=`ps -auxww | grep "Microsoft Word" | grep -v grep | awk '{print $2}'`
These variables can then be put in your .cshrc or .bashrc scripts so they're always available and always point to the correct process id.

[ Reply to This | # ]
Keep track of stopped processes via shell variables
Authored by: LC on Dec 15, '03 12:32:08PM
To shorten your shell commands, either use brackets e.g.
ps -ax | grep '[k]ext' | awk '{print $1}'
or, in sh/ksh/bash etc. it's easier to set and shift (positionals) ...
but there is --
killall [-d | -v] [-h | -?] [-help] [-l] [-m] [-s] [-u user] [-t tty] [-c procname] [-SIGNAL] [procname ...]
Also, if you started any commands from this shell (term), can just
jobs -l
then
kill %1
bg %2

etc. Larry

[ Reply to This | # ]
Keep track of stopped processes via shell variables
Authored by: LC on Dec 15, '03 12:39:15PM
Also, in a shell wrapper the pid of a launched (bg) command is available -- (csh)
some_command & ; set pid = ${!}
kill ${pid}


(sh)
pid=${!}

Larry.

[ Reply to This | # ]
Keep track of stopped processes via shell variables
Authored by: LC on Dec 15, '03 12:42:31PM
Oh yeah, to make those greps correct (in case there are multiple binaries running with similar names), need to --
ps -ax | grep '[k]ext' | head -1 | awk '{print $1}'
i.e. use head or tail to stuff just the first one into your variable; Larry.

[ Reply to This | # ]