Cuestion about process using AWK - HP UX

This is a discussion on Cuestion about process using AWK - HP UX ; Hi, I'm trying to find process to spend more than 100 second of CPU Resource, I'M ussing the command: ps -ef | grep http | awk '{if ($8=="http" && $7>="100:00") print $0}' | sort -n -k 7 But it show ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Cuestion about process using AWK

  1. Cuestion about process using AWK

    Hi, I'm trying to find process to spend more than 100 second of CPU
    Resource, I'M ussing the command:

    ps -ef | grep http | awk '{if ($8=="http" && $7>="100:00") print $0}'
    | sort -n -k 7

    But it show

    applmgr 143 9484 0 11:47:58 ? 0:34 http webfile=5,2319
    applmgr 204 9484 0 08:10:42 ? 0:56 http webfile=5,1829
    applmgr 278 9484 0 14:32:53 ? 0:04 http webfile=5,2597
    applmgr 649 9484 0 15:14:13 ? 0:09 http webfile=5,2667
    applmgr 750 9484 0 13:49:44 ? 0:43 http webfile=5,2550


    I need to show only the process who are grater than 100:00 in the
    column number 7.

    apreciate any help!!

    Regards.


  2. Re: Cuestion about process using AWK

    joel.pavon@intl.fritolay.com wrote:
    > Hi, I'm trying to find process to spend more than 100 second of CPU
    > Resource, I'M ussing the command:
    >
    > ps -ef | grep http | awk '{if ($8=="http" && $7>="100:00") print $0}'
    > | sort -n -k 7


    0:34 etc are not numeric values.

    you can always use a substr in awk to just get the first
    part (before the colon) of filed 7 and do a numeric comparision.

    This might come closer to what you are expecting.

    >
    > But it show
    >
    > applmgr 143 9484 0 11:47:58 ? 0:34 http webfile=5,2319
    > applmgr 204 9484 0 08:10:42 ? 0:56 http webfile=5,1829
    > applmgr 278 9484 0 14:32:53 ? 0:04 http webfile=5,2597
    > applmgr 649 9484 0 15:14:13 ? 0:09 http webfile=5,2667
    > applmgr 750 9484 0 13:49:44 ? 0:43 http webfile=5,2550
    >
    >
    > I need to show only the process who are grater than 100:00 in the
    > column number 7.
    >
    > apreciate any help!!
    >
    > Regards.
    >


  3. Re: Cuestion about process using AWK

    Chris Cox wrote:
    > joel.pavon@intl.fritolay.com wrote:
    >>I'm trying to find process to spend more than 100 second of CPU
    >>Resource, I'M ussing the command:
    >>
    >>ps -ef | grep http | awk '{if ($8=="http" && $7>="100:00") print $0}'

    >
    > you can always use a substr in awk to just get the first
    > part (before the colon) of filed 7 and do a numeric comparision.


    Or convert the ":" to a "." and this would be a better approximation.
    Or convert the first part then add second / 60.


  4. Re: Cuestion about process using AWK

    On Jan 30, 6:20 pm, joel.pa...@intl.fritolay.com wrote:
    > Hi, I'm trying to find process to spend more than 100 second of CPU
    > Resource, I'M ussing the command:
    >
    > ps -ef | grep http | awk '{if ($8=="http" && $7>="100:00") print $0}'
    > | sort -n -k 7
    >
    > But it show
    >
    > applmgr 143 9484 0 11:47:58 ? 0:34 http webfile=5,2319
    > applmgr 204 9484 0 08:10:42 ? 0:56 http webfile=5,1829
    > applmgr 278 9484 0 14:32:53 ? 0:04 http webfile=5,2597
    > applmgr 649 9484 0 15:14:13 ? 0:09 http webfile=5,2667
    > applmgr 750 9484 0 13:49:44 ? 0:43 http webfile=5,2550
    >
    > I need to show only the process who are grater than 100:00 in the
    > column number 7.
    >
    > apreciate any help!!
    >
    > Regards.


    First, I believe 100:00 would be 100 minutes, not seconds.

    You need to be careful with ps output. If you're going to pipe the
    results of ps to awk I'd recommend using the XPG4 syntax. Otherwise,
    when you get dates in the time field it will screw up your field
    count. For example, 'ps -ef | grep swapper' on my system shows:

    root 0 0 1 Dec 6 ? 287:51 swapper

    In your list,awk would expect 287:51 to be $7 and "swapper" to be $8,
    but they are actually $8 and $9 respectively because the date is split
    into month and day.

    Try the following:

    UNIX95= ps -C http -o time,user,ppid,pid,comm | awk -F[ :] '$NF > 6' |
    grep -v 'TIME USER'

    The 'UNIX95= ' will enable XPG4 mode. The space after the = is
    important.
    The ps -C http -o time,user,ppid,pid,comm will show only 'http'
    commands and output the columns time, user, ppid, pid and command.
    The awk -F[ :] will make spaces and colons field separators
    Tthe awk syntax will print the line if the number of fields is >6 (ie,
    the time is more than two columns -- meaning that hour:minute:seconds
    are showing).

    If you truly want greater than exactly 100 minutes, you'll have to do
    some more work in the awk syntax, but that seems a pretty arbitrary
    number so I figured -- 1 hour ~ 100 minutes, you just want to show
    processes that are using a lot of CPU.

    Jon


+ Reply to Thread