Re: grep'ping the ps output....
Hello Eric! Mon, Dec 12, 2005 at 10:04:51AM -0600 you wrote: I was wondering if someone could explain why it is sometimes there and not other times. Sometimes the ps process manages to catch the system state when grep has not been started yet by the shell. Sometimes it doesn't. And how I should correctly go about detecting if the process is running before I perform my action. You may use the -c flag of ps: -c Change the ``command'' column output to just contain the exe- cutable name, rather than the full command line. Like: [EMAIL PROTECTED]:~ ps axc |grep init 1 ?? ILs0:00,00 init -- DoubleF No virus detected in this message. Ehrm, wait a minute... /kernel: pid 56921 (antivirus), uid 32000: exited on signal 9 Oh yes, no virus:) pgpMqVIJl7TcG.pgp Description: PGP signature
Re: grep'ping the ps output....
Sergey Zaharchenko wrote: Hello Eric! Mon, Dec 12, 2005 at 10:04:51AM -0600 you wrote: I was wondering if someone could explain why it is sometimes there and not other times. Sometimes the ps process manages to catch the system state when grep has not been started yet by the shell. Sometimes it doesn't. And how I should correctly go about detecting if the process is running before I perform my action. You may use the -c flag of ps: -c Change the ``command'' column output to just contain the exe- cutable name, rather than the full command line. Like: [EMAIL PROTECTED]:~ ps axc |grep init 1 ?? ILs0:00,00 init Yes... Of course. That's the solution I'm looking for. Good thing I read over that man page before I posted my msg... Or I could've embarrassed myself. :} Thanks. -- Regards, Eric ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: grep'ping the ps output....
On Mon, December 12, 2005 11:04 am, Eric Schuele wrote: Hello, I am sure this is quite trivial, but... I have need to determine if an app (firefox, or anything really) is already running before I perform some action. So I grep the ps output. However sometimes (many times) that which I'm searching for is present in the output because I am presently grep'ing for it. But it is not always there. It seems to be a bit inconsistent. (See below). I was wondering if someone could explain why it is sometimes there and not other times. And how I should correctly go about detecting if the process is running before I perform my action. Thanks, Eric %ps | grep firefox^M^M 703 v0 I 0:00.00 /bin/sh /usr/X11R6/bin/firefox^M 722 v0 I 0:00.00 /bin/sh /usr/X11R6/lib/firefox/run-mozilla.sh /usr/X1^ M 734 v0 S 0:10.92 /usr/X11R6/lib/firefox/firefox-bin^M %ps | grep firefox^M^M 703 v0 I 0:00.00 /bin/sh /usr/X11R6/bin/firefox^M 722 v0 I 0:00.00 /bin/sh /usr/X11R6/lib/firefox/run-mozilla.sh /usr/X1^ M 734 v0 S 0:10.92 /usr/X11R6/lib/firefox/firefox-bin^M 1230 p1 RV 0:00.00 grep firefox (csh)^M SNIP You probably want something more like this: ps | grep firefox-bin | grep -v grep piping the first output set back into grep -v grep filters out any entry that matches the token grep, pulling out the one you're trying to avoid. HTH Lou -- Louis LeBlanc [EMAIL PROTECTED] Fully Funded Hobbyist, KeySlapper Extrordinaire :þ http://www.keyslapper.net Ô¿Ô¬ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: grep'ping the ps output....
Eric Schuele wrote: Hello, I am sure this is quite trivial, but... I have need to determine if an app (firefox, or anything really) is already running before I perform some action. So I grep the ps output. However sometimes (many times) that which I'm searching for is present in the output because I am presently grep'ing for it. But it is not always there. It seems to be a bit inconsistent. (See below). I was wondering if someone could explain why it is sometimes there and not other times. And how I should correctly go about detecting if the process is running before I perform my action. ps | egrep firefox | egrep -v egrep I can't explain exactly why. It's clearly a timing thing. I guess if the ps runs quickly enough then perhaps the grep hasn't actually been started by the shell. Or if ps iterates over something, then maybe the grep appears in a part of the list that has already been looked at by ps. --Alex ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: grep'ping the ps output....
On Monday 12 December 2005 10:16, Alex Zbyslaw wrote: ps | egrep firefox | egrep -v egrep Ouch! Replace that with: ps | grep [f]irefox which will never match the grep commandline itself. -- Kirk Strauser The Day Companies ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: grep'ping the ps output....
Alex Zbyslaw wrote: Eric Schuele wrote: Hello, I am sure this is quite trivial, but... I have need to determine if an app (firefox, or anything really) is already running before I perform some action. So I grep the ps output. However sometimes (many times) that which I'm searching for is present in the output because I am presently grep'ing for it. But it is not always there. It seems to be a bit inconsistent. (See below). I was wondering if someone could explain why it is sometimes there and not other times. And how I should correctly go about detecting if the process is running before I perform my action. ps | egrep firefox | egrep -v egrep Thanks guys. Yes... both solutions do fix the problem. Hmm... guess I should've looked before I lept. I assumed the processes were run in order by the shell... however it appears all are started simultaneously as a group. I can't explain exactly why. It's clearly a timing thing. I guess if the ps runs quickly enough then perhaps the grep hasn't actually been started by the shell. Or if ps iterates over something, then maybe the grep appears in a part of the list that has already been looked at by ps. --Alex ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] -- Regards, Eric ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: grep'ping the ps output....
Kirk Strauser wrote: On Monday 12 December 2005 10:16, Alex Zbyslaw wrote: ps | egrep firefox | egrep -v egrep Ouch! Replace that with: ps | grep [f]irefox Ah, yes. Very nice. Thanks. which will never match the grep commandline itself. -- Regards, Eric ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: grep'ping the ps output....
On 2005-12-12 10:04, Eric Schuele [EMAIL PROTECTED] wrote: Hello, I am sure this is quite trivial, but... I have need to determine if an app (firefox, or anything really) is already running before I perform some action. So I grep the ps output. However sometimes (many times) that which I'm searching for is present in the output because I am presently grep'ing for it. But it is not always there. It seems to be a bit inconsistent. (See below). I was wondering if someone could explain why it is sometimes there and not other times. And how I should correctly go about detecting if the process is running before I perform my action. pgrep(1) is nice for this sort of thing :) %ps | grep firefox^M^M 703 v0 I 0:00.00 /bin/sh /usr/X11R6/bin/firefox^M 722 v0 I 0:00.00 /bin/sh /usr/X11R6/lib/firefox/run-mozilla.sh /usr/X1^ M 734 v0 S 0:10.92 /usr/X11R6/lib/firefox/firefox-bin^M %ps | grep firefox^M^M 703 v0 I 0:00.00 /bin/sh /usr/X11R6/bin/firefox^M 722 v0 I 0:00.00 /bin/sh /usr/X11R6/lib/firefox/run-mozilla.sh /usr/X1^ A similar thing with pgrep(1) works as expected: % flame:/home/keramida$ for count in 1 2 3 4 5 ; do % pgrep firefox ; echo ; sleep 1 ; done % 1470 % % 1470 % % 1470 % % 1470 % % 1470 % % flame:/home/keramida$ for count in 1 2 3 4 5 ; do % pgrep -l firefox ; echo ; sleep 1 ; done % 1470 firefox-bin % % 1470 firefox-bin % % 1470 firefox-bin % % 1470 firefox-bin % % 1470 firefox-bin % % flame:/home/keramida$ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]