how to grep parent process PID in shell scripting

hi all,

for an example:
$ ps -ef | grep apache | awk '{ print $2, $3 }'
24073 11784
28021 1
28022 1
28038 1
28041 28040
28045 28041
28047 28041
28040 1
28049 28041
28051 28041
28053 28041
28030 1
28054 28041
28055 28041
28056 28041
28057 28041
28061 28039
28065 28041
28066 28041
28067 28041
28068 28041
28069 28041
28070 28041
28071 28041
28078 28041
28080 28041

I want to display only the second columns showing "1" assocaited PID's
in our case output should show:
28021 1
28022 1
28038 1
28040 1
28030 1

Extending your awk statement.

 
$ ps -ef | grep apache | awk '{ if($2==1) {print $2, $3 }}' 

replace awk with...

awk '$3==1{print $2 $3}'

---------- Post updated at 05:47 PM ---------- Previous update was at 05:46 PM ----------

I think he needs $3 as 1 and not $2, please see.

Yes :slight_smile: ...

panyam thanks a ton!!!
it works as I expected..

no need for grep AND awk:

ps -ef | awk '/apache/ && $3==1 { print $2, $3 }'