Article View: comp.unix.admin
Article #4033Re: Yet another Q. about 'grep'
From: Ken Pizzini
Date: Wed, 15 Jul 1998 00:00
Date: Wed, 15 Jul 1998 00:00
45 lines
2874 bytes
2874 bytes
On Tue, 14 Jul 1998 22:44:29 GMT, Wayne Throop <throopw@sheol.org> wrote: >:: I you are going to do a >:: ps -ef | grep 'something' >:: and you don't wanna see the grep 'something', >:: but only the true result - what are you going to write >:: to left out the 'grep' line ?????? > >: Christian Tremblay <chris@terax.com> >: ps -ef | grep 'something' | grep -v grep ps -ef | grep '[s]omething' >Or, since what you do is ensure the ps process doesn't include >the grep process in the ultimate output, ensure the grep isn't >running when the ps runs. I have a pipe fitting for that, > > ps -ef | pseq | grep something > > (where "pseq" acts like (cat >tmp; cat tmp; rm tmp)) It's still a race condition that you might pick up the grep, though the timing is more favorable to it being missed. >Note, I made myself a pseq when I had a case where a writer blew up >ungracefully if ever a reader of its stdout didn't read all the way >to the end (that is, behaved ungracefully upon receipt of a SIGPIPE). >Thus, the pipe fitting to make an panic-prone writer cooperate >with a lazy reader; also useful in this case. Wouldn't it be better to implement pseq like (cat; exec cat >/dev/null) ? (I.e., copy stdin to stdout; when the first cat dies (due to SIGPIPE or EOF, copy the remainer of stdin to /dev/null.) (Better still if this is implemented in C or perl so that the second ``cat'' equivalent does not get run if the first one quits due to EOF; it won't make a difference in a pipeline, but it'd be much better should pseq ever is used with a tty on stdin.) This avoids the creation of a potentially huge temp file, and allows the process(es) to the right of the pseq to run in parallel with the process(es) to the left, while still isolating the process(es) on the left from SIGPIPE misbehavior. --Ken Pizzini
Technical Details
Message-ID:
<slrn6qo7js.pvh.ken@pulsar.halcyon.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6of1oa$e52$1@news.uni-c.dk> <Pine.SV4.3.96.980714174758.15112A-100000@terax.com> <900456269@sheol.org>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8c9b,54c788f7d8e9c885 X-Google-Attributes: gidf8c9b,public X-Google-Thread: fc89c,54c788f7d8e9c885 X-Google-Attributes: gidfc89c,public X-Google-Thread: f72b0,54c788f7d8e9c885 X-Google-Attributes: gidf72b0,public X-Google-Thread: 11035d,54c788f7d8e9c885 X-Google-Attributes: gid11035d,public X-Google-Thread: 1020c6,54c788f7d8e9c885 X-Google-Attributes: gid1020c6,public X-Google-Thread: 10e23a,54c788f7d8e9c885 X-Google-Attributes: gid10e23a,public From: ken@halcyon.com (Ken Pizzini) Subject: Re: Yet another Q. about 'grep' Date: 1998/07/15 Message-ID: <slrn6qo7js.pvh.ken@pulsar.halcyon.com> X-Deja-AN: 371569146 References: <6of1oa$e52$1@news.uni-c.dk> <Pine.SV4.3.96.980714174758.15112A-100000@terax.com> <900456269@sheol.org> Organization: _ Reply-To: ken@halcyon.com Newsgroups: comp.unix.admin,comp.unix.misc,comp.unix.programmer,comp.unix.questions,comp.unix.solaris,dk.edb.unix