cancel
Showing results for 
Search instead for 
Did you mean: 

PID Number in the TOP

 
SOLVED
Go to solution
Highlighted
clefeitosa
Regular Advisor

PID Number in the TOP

Hello experts!

I'm using HPUX 11i.

Please I would like to know how can I get the PID number in the TOP... For example

host:> top -h

CPU TTY PID USERNAME PRI NI SIZE RES STATE TIME %WCPU %CPU
3 ? 13538 oracle9i 154 20 643M 7764K sleep 0:40 4.98 4.97 oracledbscmdes
1 ? 5819 root 154 20 9632K 2848K sleep 1514:55 3.17 3.16 cupsd
0 ? 7125 root 154 20 12024K 3140K sleep 433:13 2.90 2.89 netmon
0 ? 29685 oracle9i 154 20 800M 1788K sleep 33:15 2.36 2.36 oracledbslade1

In this case I need the 13538 PID number!
By command line is it possible to get this PID number?

Please, could someone give me a help?

Thanks!
16 REPLIES 16
Highlighted
A. Clay Stephenson
Acclaimed Contributor

Re: PID Number in the TOP

You can use top -f filename to output to a file and then use awk to extract the PID's.
If it ain't broke, I can fix that.
Highlighted
clefeitosa
Regular Advisor

Re: PID Number in the TOP

Thanks for reply!

Sorry, but could you show an example because my problem is exactly this... I'm not obtaining to extract the first PID on the TOP...

Thanks!!!!
Highlighted
Pete Randall
Outstanding Contributor

Re: PID Number in the TOP

Unless I'm missing something, the -f switch adds nothing to the normal display, it just redirects the output to a file. The only way I know of to get the parent is to select the process you are interested in from the top output and then run ps against it:

ps -ef |grep 13538


Pete

Pete
Highlighted
Pete Randall
Outstanding Contributor

Re: PID Number in the TOP

Ahhh, that's where the confusion is coming from. I think the author means PPID of the PID in question!!


Pete

Pete
Highlighted
Ignacio Javier
Regular Advisor
Solution

Re: PID Number in the TOP


Hi clefeitosa:

You could open the file and remove all the lines until PID inclusive, save the file and then execute:

cat | awk -F" " '{print $2}'
Highlighted
A. Clay Stephenson
Acclaimed Contributor

Re: PID Number in the TOP

The other thing that -f does is NOT SEND terminal escape sequences that you definitely don't want in your output when you are trying to parse it.
If it ain't broke, I can fix that.
Highlighted
Scot Bean
Honored Contributor

Re: PID Number in the TOP

Or, 'ps -ef |grep 13538'
Highlighted
Dennis Handly
Acclaimed Contributor

Re: PID Number in the TOP

Instead of using grep with ps, you can do it directly: ps -fp 13538

But grep will find the children of that PID.
Highlighted
Arturo Galbiati
Esteemed Contributor

Re: PID Number in the TOP

Hi,
top -h -f top.out
awk 'NF>12&&!/^CPU/ {print $3}' top.out

This to have all the PID, if you want only the first:
awk 'NF>12&&!/^CPU/ {print $3}' top.out|head -1

HTH,
Art