Linux Gurus - Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dusen
    Confirmed User
    • Aug 2002
    • 2251

    #1

    Linux Gurus - Problem

    I'm exec()'ing a bourne shell program from PHP. For the moment, it is not possible to port this shell program to php. I also do not have access to the source.

    The shell program is fed instructions from the php file which grabs them from a ascii file. The simplified php process is:

    while not eof datafile
    {
    fgets(arg)
    exec(program arg)
    }

    However, executing the program sometimes gets locked into loops where it will just sit there. I want to have some way to put a time limit.

    Setting the script to call another php script (that only execs the program) with a maximum exec time will not work - max times are only while inside the php script.

    And the bash ulimit can only control processor time used, not actually kill the program, correct?

    Ideally I'd like do run something like:

    exec (./timelimit5 program arg)

    which would just kill the process if it exceeds 5 seconds.

    But I'm lost. Any suggestions?
    Penis Pill Sponsor List and Reviews:
    http://www.pillsponsors.com
  • Benja
    Confirmed User
    • May 2002
    • 258

    #2
    I'm not a Linux guru, but aren't shell programs unix commands in a plain file ? Shell programs are not compiled are they ? So you should have the source and be able to put a kind of timeout there no?

    Well, just what I see from your post.
    "Bite my shiny metal ass!"

    Comment

    • flexor
      Registered User
      • Jan 2004
      • 8

      #3
      First of all, I would recomand rewriting it in Perl.

      If you want to keep it in bash, try to use signals, something like this http://www.signaltonoise.net/library...ariables2.html

      Or search Google for "bash timeout script"

      [in a nutshell]

      TimerOn()
      { ( o p e n accolade thingy here, obfuscate by GFY board code)
      sleep $TIMELIMIT && kill -s 14 $$ &
      # Waits XXX seconds, then sends sigalarm to script.
      }

      [...]
      trap Int14Vector 14
      #Int14Vector is a function called when sig 14 is traped by script


      See sleep, kill and trap for details.



      HIH

      Comment

      • Dusen
        Confirmed User
        • Aug 2002
        • 2251

        #4
        I apologize - judging from the replies - I wasn't clear.

        The program I am execing is a compiled C app under bash, it isn't a bash script. That is why I don't have the source. I can't rewrite it

        flexor - thanks for the reply though, I will put that stuff into my "learning" notebook I keep for when I'm doing something in perl.
        Penis Pill Sponsor List and Reviews:
        http://www.pillsponsors.com

        Comment

        • Babaganoosh
          ♥♥♥ Likes Hugs ♥♥♥
          • Nov 2001
          • 15841

          #5
          Check out "alarm" at http://void.lv/tools/

          It should do what you need.
          I like pie.

          Comment

          • Dusen
            Confirmed User
            • Aug 2002
            • 2251

            #6
            Alarm did it. Many many many thanks.

            Penis Pill Sponsor List and Reviews:
            http://www.pillsponsors.com

            Comment

            Working...