lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 2013-08-26 09:34:46 +0000, Sean Conner said:


It was thus said that the Great Philipp Kraus once stated:

Hello,


I'm using LUA for a simulation on a cluster system, so my user can define

their own scripts. In some cases there exists a infinite loop or infinity

recursion in the LUA code so the simulation does not stop anymore. My idea

is to create a maximum execution time (like PHP) with a watchdog (I don't

use a formal verification of the code e.g. wp-calculus). Each script has

got a defined function which is called by my C++ class, so I would like to

send the LUA script a "warning" that the max. execution time is reached,

but if the script does not stop, the C++ side should stop the script.


Can I / How can I stop a running script from C side? Do you think it is a

good idea to send a warning first, because the script does not use

threads, so IMHO the warning can not be handled by the script? I hope for

some ideas


  If you are using Unix, I can think of two ways that don't involve mucking

with Lua.


Sorry, the system must run on OSX, Linux  Windows.


  1). SIGALRM---set a handler for SIGALRM (signal() or sigaction()), then

before running your script, trigger SIGALRM for the maximum amount of wall

time you think the script needs (using either alarm() or setitimer()).  When

the alarm goes off, your signal handler will get control.  


  2). Run the script in its own process, but set a CPU resource limit to the

maximum amount of CPU time [1] the process can run.  The process may be able

to catch SIGXCPU (CPU time exceeded) to know that it has exceeded its

allowable amount of time, but I'm not sure what, exactly, will happen if the

CPU time is exceeded (and thus, you have no more CPU to run).


  I'm not sure if it's a good idea to allow the script to check, because

what can the script do?  


The scripts are "agent systems" [1], so it is correct, that some scripts do nothing.

But I need the detection for an infinity loop, because this breaks the whole simulation

process, but I can not break, if one script breaks, the full simulation process, only

the script should be stopped




[1] http://en.wikipedia.org/wiki/Software_agent