How to find out if process is in a loop? - Aix

This is a discussion on How to find out if process is in a loop? - Aix ; Is there a way to find out if the process is in an infinite loop? We have a development environment where a programmer may make a change that puts application in an infinite loop where it uses up lots of ...

+ Reply to Thread
Results 1 to 9 of 9

Thread: How to find out if process is in a loop?

  1. How to find out if process is in a loop?


    Is there a way to find out if the process is in an infinite loop?

    We have a development environment where a programmer may make a change
    that puts application in an infinite loop where it uses up lots of CPU
    but no I/O at all.

    I can think of couple of ways to determine if the application (atleast our
    application) is looping:

    1) Take a snapshot every few seconds and see if there was any I/O done.

    2) Take a snapshot every few seconds and see if the elapsed time is same as
    CPU time.

    I tried to look at /proc file system but could not find anything I could
    use.

    Are there any APIs or applications I can use to determine if the program is
    in an infinite loop?


    Thanks.

    --
    Hemant Shah /"\ ASCII ribbon campaign
    E-mail: NoJunkMailshah@xnet.com \ / ---------------------
    X against HTML mail
    TO REPLY, REMOVE NoJunkMail / \ and postings
    FROM MY E-MAIL ADDRESS.
    -----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
    I haven't lost my mind, Above opinions are mine only.
    it's backed up on tape somewhere. Others can have their own.

  2. Re: How to find out if process is in a loop?

    Hemant Shah wrote:
    > Is there a way to find out if the process is in an infinite loop?
    >
    > We have a development environment where a programmer may make a change
    > that puts application in an infinite loop where it uses up lots of CPU
    > but no I/O at all.
    >
    > I can think of couple of ways to determine if the application (atleast our
    > application) is looping:
    >
    > 1) Take a snapshot every few seconds and see if there was any I/O done.
    >
    > 2) Take a snapshot every few seconds and see if the elapsed time is same as
    > CPU time.
    >
    > I tried to look at /proc file system but could not find anything I could
    > use.
    >
    > Are there any APIs or applications I can use to determine if the program is
    > in an infinite loop?


    How about attaching to the process via truss/gdb/dbx?
    Admittedly the output is a bit hard to read, but if your
    process is in a "small" loop, like fork()/close() you'll
    see that right away.

    Regards,

    Frank

  3. Re: How to find out if process is in a loop?

    On 2006-11-10, Hemant Shah wrote:

    > Is there a way to find out if the process is in an infinite loop?


    For a random process, no, there's no way to find out.

    For a particular process (of which you have the source code), there
    might be a way: check the code for possible infinite loops. Note
    that there are loops which may be infinite, but there's no way to
    tell for sure.

    --
    Jurjen Oskam

  4. Re: How to find out if process is in a loop?

    While stranded on information super highway Jurjen Oskam wrote:
    > On 2006-11-10, Hemant Shah wrote:
    >
    >> Is there a way to find out if the process is in an infinite loop?

    >
    > For a random process, no, there's no way to find out.
    >
    > For a particular process (of which you have the source code), there
    > might be a way: check the code for possible infinite loops. Note
    > that there are loops which may be infinite, but there's no way to
    > tell for sure.


    I have the source code, and the problem occurs when programmer
    makes change to the application and runs it. The programmer may not monitor
    the program so as sys admin I want to be able to catch it before it affects
    other users.

    >
    > --
    > Jurjen Oskam


    --
    Hemant Shah /"\ ASCII ribbon campaign
    E-mail: NoJunkMailshah@xnet.com \ / ---------------------
    X against HTML mail
    TO REPLY, REMOVE NoJunkMail / \ and postings
    FROM MY E-MAIL ADDRESS.
    -----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
    I haven't lost my mind, Above opinions are mine only.
    it's backed up on tape somewhere. Others can have their own.

  5. Re: How to find out if process is in a loop?

    On 2006-11-12, Hemant Shah wrote:

    > I have the source code, and the problem occurs when programmer
    > makes change to the application and runs it. The programmer may not monitor
    > the program so as sys admin I want to be able to catch it before it affects
    > other users.


    My point was: you can't tell whether a program is in an infinite loop from the
    outside. With knowledge about how the program *should* behave, you can try to
    determine whether the program still functions correctly. For example, if the program
    was designed to write a line to a file every 5 seconds, you know there's something
    wrong when this doesn't happen. But even then, the problem might not be in the
    program itself: the machine it's running on may be overloaded.

    Your best solution is to think of a way to monitor the program from a script.
    You need to find criteria to determine if the program is still correctly running,
    and this depends greatly on the particular program.

    --
    Jurjen Oskam

  6. Re: How to find out if process is in a loop?

    In General, the problem of finding whether a problem is in an infinite
    loop or not is np hard. Can't be done. For more information refer
    "introduction to theory of computation" - Ullman.

    What i normally would do is to start kdb command and see the stack of
    the program which i suspect to be in an infinite loop. If i keep seeing
    the same stack repeatedly something is a problem.
    Then I see how much cpu the process is using. If its exceptionally
    high, then there is a good chance it is in an infinite loop.
    Of course, the last thing I would do is to actually go to the code from
    the stack trace in either kdb, or if i wanted more information what is
    going on, I would make a debug build of the program and attach dbx to
    it and analyse. That normally how I work.
    But there definitely is no sure shot way of knowing whether a program
    is going into an infinite loop or not.

    Thanks and regards,
    Rajbir Bhattacharjee

    Jurjen Oskam wrote:
    > On 2006-11-12, Hemant Shah wrote:
    >
    > > I have the source code, and the problem occurs when programmer
    > > makes change to the application and runs it. The programmer may not monitor
    > > the program so as sys admin I want to be able to catch it before it affects
    > > other users.

    >
    > My point was: you can't tell whether a program is in an infinite loop from the
    > outside. With knowledge about how the program *should* behave, you can try to
    > determine whether the program still functions correctly. For example, if the program
    > was designed to write a line to a file every 5 seconds, you know there's something
    > wrong when this doesn't happen. But even then, the problem might not be in the
    > program itself: the machine it's running on may be overloaded.
    >
    > Your best solution is to think of a way to monitor the program from a script.
    > You need to find criteria to determine if the program is still correctly running,
    > and this depends greatly on the particular program.
    >
    > --
    > Jurjen Oskam



  7. Re: How to find out if process is in a loop?

    On most Unix variants, you can do the following:
    ps -ef | sort -n -k 4 | tail

    Check if your process is in the list from the above output. Rerun the
    command and see if the fourth column (C) increases. If it keeps
    increasing, then you most likely have a program in a loop.

    Hemant Shah wrote:
    > Is there a way to find out if the process is in an infinite loop?
    >
    > We have a development environment where a programmer may make a change
    > that puts application in an infinite loop where it uses up lots of CPU
    > but no I/O at all.
    >
    > I can think of couple of ways to determine if the application (atleast our
    > application) is looping:
    >
    > 1) Take a snapshot every few seconds and see if there was any I/O done.
    >
    > 2) Take a snapshot every few seconds and see if the elapsed time is same as
    > CPU time.
    >
    > I tried to look at /proc file system but could not find anything I could
    > use.
    >
    > Are there any APIs or applications I can use to determine if the program is
    > in an infinite loop?
    >
    >
    > Thanks.
    >
    > --
    > Hemant Shah /"\ ASCII ribbon campaign
    > E-mail: NoJunkMailshah@xnet.com \ / ---------------------
    > X against HTML mail
    > TO REPLY, REMOVE NoJunkMail / \ and postings
    > FROM MY E-MAIL ADDRESS.
    > -----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
    > I haven't lost my mind, Above opinions are mine only.
    > it's backed up on tape somewhere. Others can have their own.



  8. Re: How to find out if process is in a loop?

    Here's method I use on occassion:

    1) Get the PID of the process in question (i.e. the process of the
    program you are running)

    2) truss -p PID > /tmp/truss.out 2>&1

    3) sort /tmp/truss.out | uniq -c

    The output of last command will be a list of system calls with the
    number of times they repeated in the left hand column. If the process
    is hung in in a loop, you will generally see a small amount of system
    calls repeating over and over. If the output is widely varied, then
    you can generally conclude there is no looping.

    Brent


  9. Re: How to find out if process is in a loop?


    Jurjen Oskam wrote:
    > On 2006-11-12, Hemant Shah wrote:
    >
    > > I have the source code, and the problem occurs when programmer
    > > makes change to the application and runs it. The programmer may not monitor
    > > the program so as sys admin I want to be able to catch it before it affects
    > > other users.

    >
    > My point was: you can't tell whether a program is in an infinite loop from the
    > outside. With knowledge about how the program *should* behave, you can try to
    > determine whether the program still functions correctly. For example, if the program
    > was designed to write a line to a file every 5 seconds, you know there's something
    > wrong when this doesn't happen. But even then, the problem might not be in the
    > program itself: the machine it's running on may be overloaded.
    >
    > Your best solution is to think of a way to monitor the program from a script.
    > You need to find criteria to determine if the program is still correctly running,
    > and this depends greatly on the particular program.
    >
    > --
    > Jurjen Oskam


    The "preferred" way to do this sort of thing if you have the source is
    by using tprof, which can tell you in which subroutines the program
    spent the most time. It is in the bos.perf.tools fileset on 5.3.


+ Reply to Thread