AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
 View Only
  • 1.  AIX ps duplicate instances return

    Posted Thu June 30, 2011 09:39 AM

    Originally posted by: CarlosMaynero


    Hello,

    I'm trying to know where is the difference between two AIX systems where when I run this code script test_ps.ksh with nohup:

    b=`ps -fem | grep -i prueba_ps.ksh | grep -v grep | wc -l `
    echo $b
    a=`ps -fem | grep -i prueba_ps.ksh | grep -v grep | wc -l | xargs -i expr {} - 1 `
    echo $a

    In one system it seems ok returning {1,0} values, however other systems return higher values like {2,1}. Why? Could you help me? I'm really getting mad with it, so many days asking me why this could be...

    Thanks,
    Carlos.
    #AIX-Forum


  • 2.  Re: AIX ps duplicate instances return

    Posted Mon July 04, 2011 04:50 AM

    Originally posted by: MarkTaylor


    Why don't you actually dump the output of the ps command so you can see the differences ?

    wc -l ?? you know grep has the -c flag right ?

    Rgds
    Mark Taylor
    #AIX-Forum


  • 3.  Re: AIX ps duplicate instances return

    Posted Mon July 04, 2011 08:19 AM

    Originally posted by: Maynero


    Hi, the dump is right, but the problem is with wc -l either grep -c flag. The same problem. I've changed the code script test_carlos_ps.ksh to:

    ps -fe|grep -i test_carlos_ps.ksh | grep -v grep
    a=`ps -fe | grep -i -c test_carlos_ps.ksh | grep -v grep `
    echo $a
    I do nohup test_carlos_ps.ksh and the output is:

    rating 635008 1429644 4 11:53:26 pts/9 0:00 sh -- ./test_carlos_ps.ksh
    2

    This "2" value is wrong, must be 1!!, Depends of the execution it could change correctly 1 and sometimes even 3!. I think it's an AIX bug. Don't you think? I am testing in a multi-processor machine.
    #AIX-Forum


  • 4.  Re: AIX ps duplicate instances return

    Posted Mon July 04, 2011 08:47 AM

    Originally posted by: SystemAdmin


    do yourself (and us) a favour and run the ps command ONCE
    THEN compare ps output and count of lines matching.
    you get a pattern that does not match the grep command as a bonus...

    
    match=$(ps -ef | grep [t]est_carlos_ps.ksh)   countmatch=$(echo 
    "$match"|wc -l)
    


    now if $countmatch is not equal 1 you can investigate the original command output in $match . nice huh?

    if you ask me, your carlos santana script runs sub-processes and your grep catches the process during fork(), before exec(). make sense of this before reporting an aix bug.
    #AIX-Forum


  • 5.  Re: AIX ps duplicate instances return

    Posted Mon July 04, 2011 09:28 AM

    Originally posted by: Maynero


    Hi Delgado,

    I did what you said and countmatch is not 1, it's value is 2.

    Then $match output is two processes:

    rating 942094 983120 0 15:17:30 pts/11 0:00 sh -- ./test_carlos2_ps.ksh
    rating 983120 1355786 3 15:17:30 pts/11 0:00 sh -- ./test_carlos2_ps.ksh

    You seem right but this problem I don't have in TRU Systems, then could you suggest me how to solve it if it's because grep cautches too many processes? I'm still thinking in seeing only just one process running...

    Thank you
    #AIX-Forum


  • 6.  Re: AIX ps duplicate instances return

    Posted Mon July 04, 2011 10:02 AM

    Originally posted by: SystemAdmin


    Hi Carlos,

    like I suspected. what you see is a parent and a child process (see PID and PPID column).

    easy answer: do not start processes in your script. that's what your TRU system probably does (or does fast enough).

    hard answer: rethink what you do. maybe it's sufficient to confirm your script is running at least once...

    peace
    D.
    #AIX-Forum