Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!zog.cs.cmu.edu!tgl From: tgl@zog.cs.cmu.edu (Tom Lane) Newsgroups: comp.sys.hp Subject: Re: HP-UX 7.0 problems with ps(1) and awk(1) in pipe Summary: Easier to use a temp file Message-ID: <10262@pt.cs.cmu.edu> Date: 15 Aug 90 23:35:44 GMT References: <90222.183205QQ11@LIVERPOOL.AC.UK> <-286539949@hpcupt1.HP.COM> Organization: Carnegie-Mellon University, CS/RI Lines: 35 In article <-286539949@hpcupt1.HP.COM>, jonb@hpcupt1.HP.COM (Jon Bayh) writes: > Alan Thew of the University of Liverpool Computer Laboratory writes: > > > > set exists=`ps -uqq11 | awk '$4 == "getus.csh" && $1 != x { print $1 }' x=$$ -` > > > > This worked fine at HP-UX 3.1 but at 7.0 a "spurious" PID is found > > (presumably as a result of executing part of the above pipe). The > > resulting kill(1) fails since the process is already dead. > > [Jon explains that the ps is spotting the subprocess forked to exec() awk, > before the latter has been able to do the exec; it still has the shell > script name. He suggests a couple of rather ugly solutions.] I've run into related problems in scripts for regular sh. A cleaner fix than either of Jon's is to direct ps's output into a temporary file: ps >/tmp/psout$$ set exists=`awk 'awk program' !cs.cmu.edu!tgl BITNET: tgl%cs.cmu.edu@cmuccvma CompuServe: >internet:tgl@cs.cmu.edu