Patrick, On Thursday 12 August 2004 20:00, Patrick Shanahan wrote:
* Randall R Schulz
[08-12-04 19:51]: On Thursday 12 August 2004 17:33, Patrick Shanahan wrote:
and a handy script 'psfind' 'ps aux|grep -i $1'
True, but the output of the pipeline includes the "grep" process itself.
Another flaw is that it excludes the ps headers, which can make interpreting the output difficult, especially if you use the 'l' option. That can be overcome by using "sed" instead of grep:
-==- #!/bin/bash --norc
procPat="$1"
ps aux |sed -n -e 1p -e "/$procPat/p" -==-
which also yelds the calling process and the pipe process in addition to the headers
As I said you would if you only grep to include the target pattern. You could try to add another grep that excludes the spurious hits produced by the simple pipelin, but why bother? The pidof approach obviates all that complexity.
But using "pidof" is still superior. You get no spurious responses, you get the ps headers and you don't need a pipeline with a filter that just discards unwaqnted ps output that is simply not produced at all using the pidof technique.
I get no headers, only the process id ???
That's what pidof does. It gives the _PID_ _of_ all the processes executing a program whose base name is an argument to the command. From there you can use the PID in other commands. See the script I posted earlier in this thread.
-- Patrick Shanahan
Randall Schulz