Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to set a time limit for program execution  (Read 21618 times)

0 Members and 1 Guest are viewing this topic.

hels

    Topic Starter


    Rookie

    Re: How to set a time limit for program execution
    « Reply #30 on: July 23, 2010, 12:36:41 PM »
    Thanks mat123.

    The problem occurred when the command was run concurrently with the Java program (under Parallels on an dual core Intel Mac).

    I have now moved it to a dual core PC where it takes 140 seconds to run. This is 40 seconds above the wanted time limit of 100 seconds. But acceptable for my application.

    The remaining problem is how to access the exit status (0 or 1) from the Java program (in case it finishes before the time limit). ERRORLEVEL is not available for that purpose, since it is set by the FIND command.

    Salmon Trout

    • Guest
    Re: How to set a time limit for program execution
    « Reply #31 on: July 23, 2010, 12:40:59 PM »
    I have now moved it to a dual core PC where it takes 140 seconds to run. This is 40 seconds above the wanted time limit of 100 seconds.

    Use the right sleep.exe as I suggested and you can get the 100 seconds that you want.

    hels

      Topic Starter


      Rookie

      Re: How to set a time limit for program execution
      « Reply #32 on: July 23, 2010, 03:17:19 PM »
      Hi Salmon Trout

      The inaccurate delay (about 40%) is not caused by the sleep itself, but by the TASKLIST command being executed inside a loop (100 executions), concurrently with the Java program.

      Sleeping a few milliseconds, instead of a second, will only increase this inaccuracy since more TASKLIST calls have to be made. In fact, sleeping 2 seconds 50 times results in a delay closer to 100 seconds. The drawback of this "sleep 2" solution is of course that each execution of the Java program will take at least 2 seconds.

      mat123



        Hopeful

        Thanked: 16
        • Yes
        • Yes
        • Yes
      • Experience: Familiar
      • OS: Windows XP
      Re: How to set a time limit for program execution
      « Reply #33 on: July 23, 2010, 04:23:00 PM »
      hels
      after the tsklist|find line you need to put this
      if errorlevel 1 (do whaterver you want)



      Salmon Trout

      • Guest
      Re: How to set a time limit for program execution
      « Reply #34 on: July 23, 2010, 04:25:38 PM »
      I fear you misunderstand me

      You are doing this

      start java program
      loop
           check if java is running; if not exit loop
           increment count; if count=100 exit loop
           sleep 1 second (i.e.1000 milliseconds)
      endloop

      This takes 140 seconds

      Surely if you adjust the sleep to around (100/140) seconds - around 700 milliseconds - then the total time will come to around 100 seconds?

      Please explain where my logic is faulty




          
          

      Salmon Trout

      • Guest
      Re: How to set a time limit for program execution
      « Reply #35 on: July 23, 2010, 04:27:43 PM »
      The drawback of this "sleep 2" solution is of course that each execution of the Java program will take at least 2 seconds.

      This doesn't make sense. You start the java program once only, don't you?



      hels

        Topic Starter


        Rookie

        Re: How to set a time limit for program execution
        « Reply #36 on: July 24, 2010, 01:41:42 AM »
        You start the java program once only, don't you?
        No, the batch program will be called from another batch program in order to solve about 100 puzzles.

        Surely if you adjust the sleep to around (100/140) seconds - around 700 milliseconds - then the total time will come to around 100 seconds? Please explain where my logic is faulty
        Your logic is not faulty, but it turns out in practice that the calls of 'tasklist' slow down the whole computation substantially when the Java program is running in parallel. Besides, I would like to have a solution that is machine independent.

        after the tsklist|find line you need to put this
        if errorlevel 1 (do whaterver you want)
        This test refers to the result of 'find', not the result of the Java program execution. I want to do something like

            java Program
            if errorlevel ...        // testing the exit status of Program
           
        and also make sure the Java program doesn't run for more than 100 seconds.



        Salmon Trout

        • Guest
        Re: How to set a time limit for program execution
        « Reply #37 on: July 24, 2010, 02:12:24 AM »
        Why don't you include code in the Java program to record the start time and halt after 100 seconds?

        hels

          Topic Starter


          Rookie

          Re: How to set a time limit for program execution
          « Reply #38 on: July 24, 2010, 02:56:24 AM »
          Why don't you include code in the Java program to record the start time and halt after 100 seconds?
          The Java program (or actually Java programs) will be submitted by my students. I will use a UNIX script for testing their solutions (no problem in that: ulimit -t 100), but I also would like to provide a DOS batch program so that they can test their solutions on their own PCs.