Yosef Meller <[EMAIL PROTECTED]> writes:
ps -A | grep -i firefox > /dev/null
I think you are in danger here: your grep is a separate process and it *may* appear in the process table and be grepped (since the command line contains what you are looking for) even when firefox is not run. There is no lock that says grep does not start until ps finishes reading the process table.
ps -A does not show command line arguments, so we're safe here. But see below...
One useful trick is "egrep -i [f]irefox", another is "grep -v grep".
RedHat have /usr/bin/pgrep and /usr/bin/pkill utilities, and I have used
pname () { /bin/ps auxww | /bin/egrep "$@" | /bin/grep -v egrep
}
pnum () { pname "$@" | /bin/awk '{print $2}'
}
pkill () { kill -9 `pnum [EMAIL PROTECTED]
}
in my .bashrc since before RedHat introduced theirs.
Another, related point: your script is only good for a single-user machine. Since "ps -A" lists *all* processes then your grep may find someone else's firefox. You will be better off parsing the long output of ps and finding your own firefox. E.g. RedHat's pgrep will allow that.
OK, let's use: ps auxc | grep $USER | grep $FIREFOX
The 'c' displays the true executable name without command line args, achieving much the same effect of ps -A, and I think this is a bit more elegant.
Finally, it should be relatively easy to make your script work for any browser that supports a variant of "-remote" option. You may pass the browser and the option on the command line, or via the environment, with "firefox" and "-remote" as default values.
I guess you're right, but I don't know any other browser that suports that.
-- "No, I do not contain myself," were the final words from the set of self-excluding sets. :-)
================================================================= To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]